From 8b0472932c1cb8cb2cc46322b21c0c4e21848522 Mon Sep 17 00:00:00 2001 From: Jens Gustedt Date: Sat, 6 Sep 2014 22:07:22 -0400 Subject: add C11 mutex functions --- src/thread/mtx_trylock.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/thread/mtx_trylock.c (limited to 'src/thread/mtx_trylock.c') diff --git a/src/thread/mtx_trylock.c b/src/thread/mtx_trylock.c new file mode 100644 index 00000000..61e7694e --- /dev/null +++ b/src/thread/mtx_trylock.c @@ -0,0 +1,17 @@ +#include "pthread_impl.h" +#include + +int __pthread_mutex_trylock(mtx_t *); + +int mtx_trylock(mtx_t *m) +{ + if (m->_m_type == PTHREAD_MUTEX_NORMAL) + return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success; + + int ret = __pthread_mutex_trylock(m); + switch (ret) { + default: return thrd_error; + case 0: return thrd_success; + case EBUSY: return thrd_busy; + } +} -- cgit v1.2.1