summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/apple-source-releases/objc4/spinlocks.patch
blob: 50c6a983fe4d6ed40f7308a9e2d95841f70033fb (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- objc4-551.1/runtime/objc-os.h	2013-06-10 21:16:15.000000000 -0400
+++ ../objc4-551.1/runtime/objc-os.h	2015-01-19 01:01:36.000000000 -0500
@@ -77,27 +77,72 @@
 #   include <mach-o/getsect.h>
 #   include <mach-o/dyld_priv.h>
 #   include <malloc/malloc.h>
-#   include <os/lock_private.h>
 #   include <libkern/OSAtomic.h>
 #   include <libkern/OSCacheControl.h>
-#   include <System/pthread_machdep.h>
 #   include "objc-probes.h"  // generated dtrace probe definitions.
 
+#define __PTK_FRAMEWORK_OBJC_KEY5 45
+#define __PTK_FRAMEWORK_OBJC_KEY6 46
+#define __PTK_FRAMEWORK_OBJC_KEY7 47
+#define __PTK_FRAMEWORK_OBJC_KEY8 48
+#define __PTK_FRAMEWORK_OBJC_KEY9 49
+
+extern "C" int pthread_key_init_np(int, void (*)(void *));
+
 // Some libc functions call objc_msgSend() 
 // so we can't use them without deadlocks.
 void syslog(int, const char *, ...) UNAVAILABLE_ATTRIBUTE;
 void vsyslog(int, const char *, va_list) UNAVAILABLE_ATTRIBUTE;
 
+#if defined(__i386__) || defined(__x86_64__)
+
+// Inlined spinlock.
+// Not for arm on iOS because it hurts uniprocessor performance.
+
+#define ARR_SPINLOCK_INIT 0
+// XXX -- Careful: OSSpinLock isn't volatile, but should be
+typedef volatile int ARRSpinLock;
+__attribute__((always_inline))
+static inline void ARRSpinLockLock(ARRSpinLock *l)
+{
+    unsigned y;
+again:
+    if (__builtin_expect(__sync_lock_test_and_set(l, 1), 0) == 0) {
+        return;
+    }
+    for (y = 1000; y; y--) {
+#if defined(__i386__) || defined(__x86_64__)
+        asm("pause");
+#endif
+        if (*l == 0) goto again;
+    }
+    thread_switch(THREAD_NULL, SWITCH_OPTION_DEPRESS, 1);
+    goto again;
+}
+__attribute__((always_inline))
+static inline void ARRSpinLockUnlock(ARRSpinLock *l)
+{
+    __sync_lock_release(l);
+}
+__attribute__((always_inline))
+static inline int ARRSpinLockTry(ARRSpinLock *l)
+{
+    return __sync_bool_compare_and_swap(l, 0, 1);
+}
+
+#define spinlock_t ARRSpinLock
+#define spinlock_trylock(l) ARRSpinLockTry(l)
+#define spinlock_lock(l) ARRSpinLockLock(l)
+#define spinlock_unlock(l) ARRSpinLockUnlock(l)
+#define SPINLOCK_INITIALIZER ARR_SPINLOCK_INIT 
 
-#define spinlock_t os_lock_handoff_s
-#define spinlock_trylock(l) os_lock_trylock(l)
-#define spinlock_lock(l) os_lock_lock(l)
-#define spinlock_unlock(l) os_lock_unlock(l)
-#define SPINLOCK_INITIALIZER OS_LOCK_HANDOFF_INIT
+#endif
 
 
 #if !TARGET_OS_IPHONE
-#   include <CrashReporterClient.h>
+#define CRSetCrashLogMessage(msg)
+#define CRGetCrashLogMessage() 0
+#define CRSetCrashLogMessage2(msg)
 #else
     // CrashReporterClient not yet available on iOS
     __BEGIN_DECLS
@@ -594,21 +639,13 @@
 { 
     assert(is_valid_direct_key(k));
 
-    if (_pthread_has_direct_tsd()) {
-        return _pthread_getspecific_direct(k);
-    } else {
-        return pthread_getspecific(k);
-    }
+    return pthread_getspecific(k);
 }
 static inline void tls_set_direct(tls_key_t k, void *value) 
 { 
     assert(is_valid_direct_key(k));
 
-    if (_pthread_has_direct_tsd()) {
-        _pthread_setspecific_direct(k, value);
-    } else {
-        pthread_setspecific(k, value);
-    }
+    pthread_setspecific(k, value);
 }
 
 // not arm