summaryrefslogtreecommitdiff
path: root/src/thread/pthread_rwlock_trywrlock.c
blob: 1bcf7c998f3a113773b60e8c76ed8f1b8c841db7 (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->_rw_wrlock, 1))
		return EAGAIN;
	if (rw->_rw_readers) {
		a_store(&rw->_rw_wrlock, 0);
		return EAGAIN;
	}
	rw->_rw_owner = pthread_self()->tid;
	return 0;
}