]> pd.if.org Git - pdclib.old/blobdiff - opt/pthreads/mtx_trylock.c
Add pthreads threading backend and move the POSIX port over to using it
[pdclib.old] / opt / pthreads / mtx_trylock.c
diff --git a/opt/pthreads/mtx_trylock.c b/opt/pthreads/mtx_trylock.c
new file mode 100644 (file)
index 0000000..8a095a5
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef REGTEST
+#include <threads.h>
+#include <pthread.h>
+#include <errno.h>
+
+int mtx_trylock(mtx_t *mtx)
+{
+    switch(pthread_mutex_trylock(mtx)) {
+        case 0:
+            return thrd_success;
+        case EBUSY:
+            return thrd_busy;
+        default:
+            return thrd_error;
+    }
+}
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    return TEST_RESULTS;
+}
+
+#endif