Skip to content

Commit

Permalink
Use process-local futex operations
Browse files Browse the repository at this point in the history
The FUTEX_WAIT and FUTEX_WAKE operations are supposed to be applied to futexes that can be shared between processes. Using process-local equivalents can be more efficient.

Also add linux/futex.h include, which should nowdays be provided by all relevant Linux distributions. Since linux_common.h is also included on various BSD systems, include sys/futex.h where available and disable futex API where not.
  • Loading branch information
Lastique committed Jun 1, 2018
1 parent 633b01a commit 9a666ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions include/tbb/machine/linux_common.h
Expand Up @@ -31,18 +31,39 @@

#if defined(SYS_futex)

/*
* Note that this header is included not only on Linux. Some BSD systems may also support futexes,
* but provide the definitions in other headers.
*/
#if defined(__linux__)
#include <linux/futex.h>
#define __TBB_USE_FUTEX 1
#elif defined(__OpenBSD__)
#include <sys/futex.h>
#define __TBB_USE_FUTEX 1
#elif defined(__has_include)
#if __has_include(<sys/futex.h>)
#include <sys/futex.h>
#define __TBB_USE_FUTEX 1
#endif
#endif

#if __TBB_USE_FUTEX

#include <limits.h>
#include <errno.h>
// Unfortunately, some versions of Linux do not have a header that defines FUTEX_WAIT and FUTEX_WAKE.

#ifdef FUTEX_WAIT
#if defined(FUTEX_WAIT_PRIVATE)
#define __TBB_FUTEX_WAIT FUTEX_WAIT_PRIVATE
#elif defined(FUTEX_WAIT)
#define __TBB_FUTEX_WAIT FUTEX_WAIT
#else
#define __TBB_FUTEX_WAIT 0
#endif

#ifdef FUTEX_WAKE
#if defined(FUTEX_WAKE_PRIVATE)
#define __TBB_FUTEX_WAKE FUTEX_WAKE_PRIVATE
#elif defined(FUTEX_WAKE)
#define __TBB_FUTEX_WAKE FUTEX_WAKE
#else
#define __TBB_FUTEX_WAKE 1
Expand Down Expand Up @@ -81,4 +102,6 @@ inline int futex_wakeup_all( void *futex ) {

} /* namespace tbb */

#endif /* __TBB_USE_FUTEX */

#endif /* SYS_futex */
2 changes: 1 addition & 1 deletion include/tbb/tbb_machine.h
Expand Up @@ -227,7 +227,7 @@ template<> struct atomic_selector<8> {
#include "machine/linux_intel64.h"
#endif

#elif __linux__ || __FreeBSD__ || __NetBSD__
#elif __linux__ || __FreeBSD__ || __NetBSD__ || __OpenBSD__

#if (TBB_USE_GCC_BUILTINS && __TBB_GCC_BUILTIN_ATOMICS_PRESENT)
#include "machine/gcc_generic.h"
Expand Down

0 comments on commit 9a666ed

Please sign in to comment.