1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
From dc95322e18615392eea69de355edd735a15a8f36 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 20 Oct 2014 00:22:51 -0400
Subject: [PATCH] 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.
---
src/thread/pthread_once.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/thread/pthread_once.c b/src/thread/pthread_once.c
index 7c47385..df655ef 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);
--
2.2.0
|