Files
semi-libc/src/thread/pthread_mutexattr_setprotocol.c
T
Rich Felker 69a1b39019 drop use of pthread_once in mutexattr kernel support tests
this makes the code slightly smaller and eliminates these functions
from relevance to possible future changes to multithreaded fork.

the barrier of a_store isn't technically needed here, but a_store is
used anyway for internal consistency of the memory model.
2020-10-14 20:27:12 -04:00

29 lines
560 B
C

#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:
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;
case PTHREAD_PRIO_PROTECT:
return ENOTSUP;
default:
return EINVAL;
}
}