make pointers used in robust list volatile
[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         volatile void *volatile *p;
8         volatile void *volatile *prev;
9         volatile void *volatile *next;
10         pthread_mutex_t *m;
11
12         prev = &self->robust_list.head;
13         for (p=self->robust_list.head; p&&p!=&self->robust_list.head; p=next) {
14                 next = *p;
15                 m = (void *)((char *)p - offsetof(pthread_mutex_t, _m_next));
16                 if (!(m->_m_type & 128)) {
17                         int waiters = m->_m_waiters;
18                         *prev = next;
19                         int cont = a_swap(&m->_m_lock, self->tid|0x40000000);
20                         if (cont < 0 || waiters) __wake(&m->_m_lock, 1, 1);
21                 } else {
22                         prev = p;
23                 }
24         }
25 }
26
27 int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
28 {
29         if (robust > 1U) return EINVAL;
30         a->__attr &= ~4;
31         a->__attr |= robust*4;
32         return 0;
33 }