xref: /aosp_15_r20/external/musl/src/thread/pthread_mutexattr_setrobust.c (revision c9945492fdd68bbe62686c5b452b4dc1be3f8453)
1 #include "pthread_impl.h"
2 #include "syscall.h"
3 
4 static volatile int check_robust_result = -1;
5 
pthread_mutexattr_setrobust(pthread_mutexattr_t * a,int robust)6 int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
7 {
8 	if (robust > 1U) return EINVAL;
9 	if (robust) {
10 		int r = check_robust_result;
11 		if (r < 0) {
12 			void *p;
13 			size_t l;
14 			r = -__syscall(SYS_get_robust_list, 0, &p, &l);
15 			a_store(&check_robust_result, r);
16 		}
17 		if (r) return r;
18 		a->__attr |= 4;
19 		return 0;
20 	}
21 	a->__attr &= ~4;
22 	return 0;
23 }
24