projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
improve the quality of output from rand_r
[musl]
/
src
/
stdio
/
ftrylockfile.c
diff --git
a/src/stdio/ftrylockfile.c
b/src/stdio/ftrylockfile.c
index
1d0a1ff
..
eef4e25
100644
(file)
--- a/
src/stdio/ftrylockfile.c
+++ b/
src/stdio/ftrylockfile.c
@@
-1,18
+1,19
@@
#include "stdio_impl.h"
#include "pthread_impl.h"
#include "stdio_impl.h"
#include "pthread_impl.h"
+#include <limits.h>
int ftrylockfile(FILE *f)
{
int ftrylockfile(FILE *f)
{
- i
f (!libc.lockfile) libc.lockfile = __lockfile
;
- if (f->
owner && f->owner == pthread_self()->
tid) {
- if (f->lockcount ==
INT
_MAX)
+ i
nt tid = pthread_self()->tid
;
+ if (f->
lock ==
tid) {
+ if (f->lockcount ==
LONG
_MAX)
return -1;
f->lockcount++;
return 0;
}
return -1;
f->lockcount++;
return 0;
}
- if (a_swap(&f->lock, 1))
+ if (f->lock < 0) f->lock = 0;
+ if (f->lock || a_cas(&f->lock, 0, tid))
return -1;
return -1;
- f->owner = pthread_self()->tid;
f->lockcount = 1;
return 0;
}
f->lockcount = 1;
return 0;
}