summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c')
-rw-r--r--libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c b/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c
new file mode 100644
index 0000000..84b02ba
--- /dev/null
+++ b/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c
@@ -0,0 +1,32 @@
+#include "pthread_impl.h"
+#include "syscall.h"
+
+static volatile int check_pi_result = -1;
+
+int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
+{
+ int r;
+ switch (protocol) {
+ case PTHREAD_PRIO_NONE:
+ a->__attr &= ~8;
+ return 0;
+ case PTHREAD_PRIO_INHERIT:
+#ifdef __wasilibc_unmodified_upstream
+ r = check_pi_result;
+ if (r < 0) {
+ volatile int lk = 0;
+ r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
+ a_store(&check_pi_result, r);
+ }
+ if (r) return r;
+ a->__attr |= 8;
+ return 0;
+#else
+ return ENOTSUP;
+#endif
+ case PTHREAD_PRIO_PROTECT:
+ return ENOTSUP;
+ default:
+ return EINVAL;
+ }
+}