about summary refs log tree commit diff
path: root/pkgs/development/compilers/ghc/D2712.patch
blob: d938d70bbcfe47e94cc96e03fa58126f98b5b163 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h
--- a/includes/rts/OSThreads.h
+++ b/includes/rts/OSThreads.h
@@ -15,7 +15,12 @@
 #ifndef RTS_OSTHREADS_H
 #define RTS_OSTHREADS_H
 
-#if defined(THREADED_RTS) /* to near the end */
+#if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS)
+#define BUILD_OSTHREAD_POSIX
+#endif
+
+
+#if defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) /* to near end */
 
 #if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS)
 
@@ -205,13 +210,25 @@
 void releaseThreadNode (void);
 #endif // !CMINUSMINUS
 
-#else
+#endif /* defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) */
+
+#ifndef THREADED_RTS
+
+#ifdef ACQUIRE_LOCK
+// If we have pthreads, we pull in the threading primitives even when the RTS
+// isn't threaded, but we expect these macros to be noops on non-threaded RTS.
+
+#undef ACQUIRE_LOCK
+#undef RELEASE_LOCK
+#undef ASSERT_LOCK_HELD
+
+#endif
 
 #define ACQUIRE_LOCK(l)
 #define RELEASE_LOCK(l)
 #define ASSERT_LOCK_HELD(l)
 
-#endif /* defined(THREADED_RTS) */
+#endif
 
 #ifndef CMINUSMINUS
 //
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -35,7 +35,7 @@
 #endif
 #endif
 
-#if defined(THREADED_RTS)
+#if defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX)
 #include "RtsUtils.h"
 #include "Task.h"
 
@@ -225,47 +225,6 @@
     return NULL;
 }
 
-int
-forkOS_createThread ( HsStablePtr entry )
-{
-    pthread_t tid;
-    int result = pthread_create(&tid, NULL,
-                                forkOS_createThreadWrapper, (void*)entry);
-    if(!result)
-        pthread_detach(tid);
-    return result;
-}
-
-void freeThreadingResources (void) { /* nothing */ }
-
-uint32_t
-getNumberOfProcessors (void)
-{
-    static uint32_t nproc = 0;
-
-    if (nproc == 0) {
-#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
-        nproc = sysconf(_SC_NPROCESSORS_ONLN);
-#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
-        nproc = sysconf(_SC_NPROCESSORS_CONF);
-#elif defined(darwin_HOST_OS)
-        size_t size = sizeof(uint32_t);
-        if(sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
-            if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
-                nproc = 1;
-        }
-#elif defined(freebsd_HOST_OS)
-        size_t size = sizeof(uint32_t);
-        if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
-            nproc = 1;
-#else
-        nproc = 1;
-#endif
-    }
-
-    return nproc;
-}
-
 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
 // Schedules the thread to run on CPU n of m.  m may be less than the
 // number of physical CPUs, in which case, the thread will be allowed
@@ -353,6 +312,51 @@
     pthread_kill(id, SIGPIPE);
 }
 
+#endif /* defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) */
+
+#if defined(THREADED_RTS)
+
+int
+forkOS_createThread ( HsStablePtr entry )
+{
+    pthread_t tid;
+    int result = pthread_create(&tid, NULL,
+                                forkOS_createThreadWrapper, (void*)entry);
+    if(!result)
+        pthread_detach(tid);
+    return result;
+}
+
+void freeThreadingResources (void) { /* nothing */ }
+
+uint32_t
+getNumberOfProcessors (void)
+{
+    static uint32_t nproc = 0;
+
+    if (nproc == 0) {
+#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+        nproc = sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
+        nproc = sysconf(_SC_NPROCESSORS_CONF);
+#elif defined(darwin_HOST_OS)
+        size_t size = sizeof(uint32_t);
+        if(sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
+            if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
+                nproc = 1;
+        }
+#elif defined(freebsd_HOST_OS)
+        size_t size = sizeof(uint32_t);
+        if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
+            nproc = 1;
+#else
+        nproc = 1;
+#endif
+    }
+
+    return nproc;
+}
+
 #else /* !defined(THREADED_RTS) */
 
 int