summaryrefslogtreecommitdiff
path: root/src/stdio/flockfile.c
blob: 6b574cf0905f8ac4bd58458c2730d5e79b739634 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "stdio_impl.h"
#include "pthread_impl.h"

#define MAYBE_WAITERS 0x40000000

void flockfile(FILE *f)
{
	while (ftrylockfile(f)) {
		int owner = f->lock;
		if (!owner) continue;
		a_cas(&f->lock, owner, owner|MAYBE_WAITERS);
		__futexwait(&f->lock, owner|MAYBE_WAITERS, 1);
	}
}