]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c
threads: implement support for pthread mutexes (#315)
[wasi-libc.git] / libc-top-half / musl / src / thread / pthread_mutexattr_setprotocol.c
1 #include "pthread_impl.h"
2 #include "syscall.h"
3
4 static volatile int check_pi_result = -1;
5
6 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
7 {
8 int r;
9 switch (protocol) {
10 case PTHREAD_PRIO_NONE:
11 a->__attr &= ~8;
12 return 0;
13 case PTHREAD_PRIO_INHERIT:
14 #ifdef __wasilibc_unmodified_upstream
15 r = check_pi_result;
16 if (r < 0) {
17 volatile int lk = 0;
18 r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
19 a_store(&check_pi_result, r);
20 }
21 if (r) return r;
22 a->__attr |= 8;
23 return 0;
24 #else
25 return ENOTSUP;
26 #endif
27 case PTHREAD_PRIO_PROTECT:
28 return ENOTSUP;
29 default:
30 return EINVAL;
31 }
32 }