]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/thread/mtx_trylock.c
bump version to 0.0~git20230821.ec4566b-1~bpo12+pve1
[wasi-libc.git] / libc-top-half / musl / src / thread / mtx_trylock.c
1 #include "pthread_impl.h"
2 #include <threads.h>
3
4 int mtx_trylock(mtx_t *m)
5 {
6 if (m->_m_type == PTHREAD_MUTEX_NORMAL)
7 return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success;
8
9 int ret = __pthread_mutex_trylock((pthread_mutex_t *)m);
10 switch (ret) {
11 default: return thrd_error;
12 case 0: return thrd_success;
13 case EBUSY: return thrd_busy;
14 }
15 }