summaryrefslogtreecommitdiff
path: root/src/thread/pthread_mutexattr_setprotocol.c
blob: 511cc32d8f0ad9df99d4193901dbb514160f928e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "pthread_impl.h"
#include "syscall.h"

static pthread_once_t check_pi_once;
static int check_pi_result;

static void check_pi()
{
	volatile int lk = 0;
	check_pi_result = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
}

int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
{
	switch (protocol) {
	case PTHREAD_PRIO_NONE:
		a->__attr &= ~8;
		return 0;
	case PTHREAD_PRIO_INHERIT:
		pthread_once(&check_pi_once, check_pi);
		if (check_pi_result) return check_pi_result;
		a->__attr |= 8;
		return 0;
	case PTHREAD_PRIO_PROTECT:
		return ENOTSUP;
	default:
		return EINVAL;
	}
}