Skip to content

Commit a650657

Browse files
committed
Merge pull request swiftlang#50 from frankeh/futexes
add futex semaphore support derived from hutchinson port
2 parents 15d49f7 + a50c179 commit a650657

File tree

5 files changed

+254
-7
lines changed

5 files changed

+254
-7
lines changed

Diff for: configure.ac

+5
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ AC_CHECK_FUNC([sem_init],
291291
[have_sem_init=true], [have_sem_init=false]
292292
)
293293

294+
AC_CHECK_HEADER(linux/futex.h, [have_futex=true], [have_futex=false])
295+
294296
#
295297
# We support both Mach semaphores and POSIX semaphores; if the former are
296298
# available, prefer them.
@@ -299,6 +301,9 @@ AC_MSG_CHECKING([what semaphore type to use]);
299301
AS_IF([test "x$have_mach" = "xtrue"],
300302
[AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
301303
AC_MSG_RESULT([Mach semaphores])],
304+
[test "x$have_futex" = "xtrue"],
305+
[AC_DEFINE(USE_FUTEX_SEM, 1, [Define to use Futex semaphores])
306+
AC_MSG_RESULT([Futex semaphores])],
302307
[test "x$have_sem_init" = "xtrue"],
303308
[AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
304309
AC_MSG_RESULT([POSIX semaphores])],

Diff for: src/internal.h

+23
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
228228
#endif
229229
#include <limits.h>
230230
#include <search.h>
231+
#if USE_FUTEX_SEM
232+
#include <sys/syscall.h>
233+
#include <linux/futex.h>
234+
#endif
231235
#if USE_POSIX_SEM
232236
#include <semaphore.h>
233237
#endif
238+
234239
#include <signal.h>
235240
#include <stdarg.h>
236241
#include <stdbool.h>
@@ -242,6 +247,24 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
242247
#include <unistd.h>
243248
#endif
244249

250+
#if defined(__APPLE__)
251+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
252+
#define DISPATCH_LITTLE_ENDIAN
253+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
254+
#define DISPATCH_BIG_ENDIAN
255+
#endif
256+
#else
257+
#include <endian.h>
258+
#if __BYTE_ORDER == __LITTLE_ENDIAN
259+
#define DISPATCH_LITTLE_ENDIAN
260+
#elif __BYTE_ORDER == __BIG_ENDIAN
261+
#define DISPATCH_BIG_ENDIAN
262+
#else
263+
#error "please define DISPATCH_LITTLE_ENDIAN or DISPATCH_BIG_ENDIAN for your architecture / platform"
264+
#endif
265+
#endif /* defined(__APPLE__) */
266+
267+
245268
#ifndef __has_builtin
246269
#define __has_builtin(x) 0
247270
#endif

Diff for: src/queue.c

+2
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,8 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
879879
/* XXXRW: POSIX semaphores don't support LIFO? */
880880
int ret = sem_init(&(pqc->dpq_thread_mediator.dsema_sem), 0, 0);
881881
(void)dispatch_assume_zero(ret);
882+
#elif USE_FUTEX_SEM
883+
pqc->dpq_thread_mediator.dsema_futex = DISPATCH_FUTEX_INIT;
882884
#endif
883885
}
884886
#endif // DISPATCH_USE_PTHREAD_POOL

0 commit comments

Comments
 (0)