about summary refs log tree commit diff
path: root/src/stdio/ftrylockfile.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-24 23:16:52 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-24 23:16:52 -0400
commita37452430f93700aeb122d693959ad79d8e43ada (patch)
tree6ed8879bddb17c2b0db8c8bbd4778e11912f0767 /src/stdio/ftrylockfile.c
parentd8dc2faf1033e134e3a8f39bdf15c065f4d234be (diff)
downloadmusl-a37452430f93700aeb122d693959ad79d8e43ada.tar.gz
musl-a37452430f93700aeb122d693959ad79d8e43ada.tar.xz
musl-a37452430f93700aeb122d693959ad79d8e43ada.zip
simplify and optimize FILE lock handling
Diffstat (limited to 'src/stdio/ftrylockfile.c')
-rw-r--r--src/stdio/ftrylockfile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/stdio/ftrylockfile.c b/src/stdio/ftrylockfile.c
index 1d0a1ff8..67f4b6a0 100644
--- a/src/stdio/ftrylockfile.c
+++ b/src/stdio/ftrylockfile.c
@@ -3,16 +3,16 @@
 
 int ftrylockfile(FILE *f)
 {
+	int tid = pthread_self()->tid;
 	if (!libc.lockfile) libc.lockfile = __lockfile;
-	if (f->owner && f->owner == pthread_self()->tid) {
+	if (f->lock == tid) {
 		if (f->lockcount == INT_MAX)
 			return -1;
 		f->lockcount++;
 		return 0;
 	}
-	if (a_swap(&f->lock, 1))
+	if (f->lock || a_cas(&f->lock, 0, tid))
 		return -1;
-	f->owner = pthread_self()->tid;
 	f->lockcount = 1;
 	return 0;
 }