8948cbafbbc88268889d63569abe463fbd11ca71
[musl] / src / thread / pthread_mutexattr_setrobust.c
1 #include "pthread_impl.h"
2 #include <stddef.h>
3
4 void __do_private_robust_list()
5 {
6         pthread_t self = __pthread_self();
7         void **p, **prev, **next;
8         pthread_mutex_t *m;
9
10         for (prev=0, p=self->robust_list.head; p; p=next) {
11                 next = *p;
12                 m = (void *)((char *)p - offsetof(pthread_mutex_t, _m_next));
13                 if (!(m->_m_type & 128)) {
14                         int waiters = m->_m_waiters;
15                         if (prev) *prev = next;
16                         else self->robust_list.head = next;
17                         int cont = a_swap(&m->_m_lock, self->tid|0x40000000);
18                         if (cont < 0 || waiters) __wake(&m->_m_lock, 1, 1);
19                 } else {
20                         prev = p;
21                 }
22         }
23 }
24
25 int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
26 {
27         if (robust > 1U) return EINVAL;
28         a->__attr &= ~4;
29         a->__attr |= robust*4;
30         return 0;
31 }