1
0
Эх сурвалжийг харах

optimize file locking: avoid cache-polluting writes to global storage

Rich Felker 14 жил өмнө
parent
commit
4d9cc0b399

+ 4 - 2
src/stdio/flockfile.c

@@ -3,7 +3,9 @@
 
 void flockfile(FILE *f)
 {
-	pthread_self();
-	libc.lockfile = __lockfile;
+	if (!libc.lockfile) {
+		pthread_self();
+		libc.lockfile = __lockfile;
+	}
 	__lockfile(f);
 }

+ 1 - 1
src/stdio/ftrylockfile.c

@@ -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;