projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Add ABI compatability aliases.
[oweals/musl.git]
/
src
/
stdio
/
ftrylockfile.c
1
#include "stdio_impl.h"
2
#include "pthread_impl.h"
3
#include <limits.h>
4
5
int ftrylockfile(FILE *f)
6
{
7
int tid = pthread_self()->tid;
8
if (f->lock == tid) {
9
if (f->lockcount == LONG_MAX)
10
return -1;
11
f->lockcount++;
12
return 0;
13
}
14
if (f->lock < 0) f->lock = 0;
15
if (f->lock || a_cas(&f->lock, 0, tid))
16
return -1;
17
f->lockcount = 1;
18
return 0;
19
}