about summary refs log tree commit diff
path: root/src/thread/pthread_once.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-10-20 00:22:51 -0400
committerRich Felker <dalias@aerifal.cx>2014-10-20 00:22:51 -0400
commitdc95322e18615392eea69de355edd735a15a8f36 (patch)
tree3386437650008764e8b9a9a61c389d067a6bd3dd /src/thread/pthread_once.c
parent60a4783ed4bd0496f7eb31f9b7eb2ad10df46677 (diff)
downloadmusl-dc95322e18615392eea69de355edd735a15a8f36.tar.gz
musl-dc95322e18615392eea69de355edd735a15a8f36.tar.xz
musl-dc95322e18615392eea69de355edd735a15a8f36.zip
manually "shrink wrap" fast path in pthread_once
this change is a workaround for the inability of current compilers to
perform "shrink wrapping" optimizations. in casual testing, it roughly
doubled the performance of pthread_once when called on an
already-finished once control object.
Diffstat (limited to 'src/thread/pthread_once.c')
-rw-r--r--src/thread/pthread_once.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/thread/pthread_once.c b/src/thread/pthread_once.c
index 7c47385c..df655ef9 100644
--- a/src/thread/pthread_once.c
+++ b/src/thread/pthread_once.c
@@ -8,15 +8,8 @@ static void undo(void *control)
 		__wake(control, -1, 1);
 }
 
-int __pthread_once(pthread_once_t *control, void (*init)(void))
+int __pthread_once_full(pthread_once_t *control, void (*init)(void))
 {
-	/* Return immediately if init finished before, but ensure that
-	 * effects of the init routine are visible to the caller. */
-	if (*control == 2) {
-		a_barrier();
-		return 0;
-	}
-
 	/* Try to enter initializing state. Four possibilities:
 	 *  0 - we're the first or the other cancelled; run init
 	 *  1 - another thread is running init; wait
@@ -43,4 +36,15 @@ int __pthread_once(pthread_once_t *control, void (*init)(void))
 	}
 }
 
+int __pthread_once(pthread_once_t *control, void (*init)(void))
+{
+	/* Return immediately if init finished before, but ensure that
+	 * effects of the init routine are visible to the caller. */
+	if (*control == 2) {
+		a_barrier();
+		return 0;
+	}
+	return __pthread_once_full(control, init);
+}
+
 weak_alias(__pthread_once, pthread_once);