summaryrefslogtreecommitdiff
path: root/src/thread/pthread_rwlock_trywrlock.c
blob: c029b87408081b30c9ddcc39ed637e3b5e47d8ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "pthread_impl.h"

int pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
{
	if (a_xchg(&rw->__wrlock, 1))
		return EAGAIN;
	if (rw->__readers) {
		a_store(&rw->__wrlock, 0);
		return EAGAIN;
	}
	rw->__owner = pthread_self()->tid;
	return 0;
}