1 #include "pthread_impl.h" 2 #include "syscall.h" 3 4 static volatile int check_pi_result = -1; 5 pthread_mutexattr_setprotocol(pthread_mutexattr_t * a,int protocol)6int 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 r = check_pi_result; 15 if (r < 0) { 16 volatile int lk = 0; 17 r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0); 18 a_store(&check_pi_result, r); 19 } 20 if (r) return r; 21 a->__attr |= 8; 22 return 0; 23 case PTHREAD_PRIO_PROTECT: 24 return ENOTSUP; 25 default: 26 return EINVAL; 27 } 28 } 29