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 1b6ef5806fb78818139a509f116664ac96f0cdb8..440a36a9aecb9bfb1a08907d2c91ab9513da19e5 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 725b66e735aff23ed5e9c0a2335d677ace3374ce..1d0a1ff8662baad6ce8593348c4179530b70ca4e 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;