github.com/afumu/libc@v0.0.6/musl/src/thread/mtx_trylock.c (about)

     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  }