optimize file locking: avoid cache-polluting writes to global storage
authorRich Felker <dalias@aerifal.cx>
Wed, 16 Mar 2011 14:39:45 +0000 (10:39 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 16 Mar 2011 14:39:45 +0000 (10:39 -0400)
src/stdio/flockfile.c
src/stdio/ftrylockfile.c

index 1b6ef58..440a36a 100644 (file)
@@ -3,7 +3,9 @@
 
 void flockfile(FILE *f)
 {
-       pthread_self();
-       libc.lockfile = __lockfile;
+       if (!libc.lockfile) {
+               pthread_self();
+               libc.lockfile = __lockfile;
+       }
        __lockfile(f);
 }
index 725b66e..1d0a1ff 100644 (file)
@@ -3,7 +3,7 @@
 
 int ftrylockfile(FILE *f)
 {
-       libc.lockfile = __lockfile;
+       if (!libc.lockfile) libc.lockfile = __lockfile;
        if (f->owner && f->owner == pthread_self()->tid) {
                if (f->lockcount == INT_MAX)
                        return -1;