summaryrefslogtreecommitdiff
path: root/src/thread/pthread_mutexattr_setrobust.c
blob: 8948cbafbbc88268889d63569abe463fbd11ca71 (plain)
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
30
31
#include "pthread_impl.h"
#include <stddef.h>

void __do_private_robust_list()
{
	pthread_t self = __pthread_self();
	void **p, **prev, **next;
	pthread_mutex_t *m;

	for (prev=0, p=self->robust_list.head; p; p=next) {
		next = *p;
		m = (void *)((char *)p - offsetof(pthread_mutex_t, _m_next));
		if (!(m->_m_type & 128)) {
			int waiters = m->_m_waiters;
			if (prev) *prev = next;
			else self->robust_list.head = next;
			int cont = a_swap(&m->_m_lock, self->tid|0x40000000);
			if (cont < 0 || waiters) __wake(&m->_m_lock, 1, 1);
		} else {
			prev = p;
		}
	}
}

int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
{
	if (robust > 1U) return EINVAL;
	a->__attr &= ~4;
	a->__attr |= robust*4;
	return 0;
}