Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use process-local futex operations #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions include/tbb/machine/linux_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,37 @@

#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. For backward compatibility we also support
* systems that don't provide any header but support futexes, as indicated by the SYS_futex macro.
*/
#define __TBB_USE_FUTEX 1

#if defined(__linux__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will slightly refactor this part of the code, à la:

#if defined(__has_include)
#define __TBB_has_include __has_include
#else
#define __TBB_has_include(x) 0
#endif

#if defined(__linux__) || __TBB_has_include(<linux/futex.h>)
#include <linux/futex.h>
#elif defined(__OpenBSD__) || __TBB_has_include(<sys/futex.h>)
#include <sys/futex.h>
#endif

#include <linux/futex.h>
#elif defined(__OpenBSD__)
#include <sys/futex.h>
#elif defined(__has_include)
#if __has_include(<sys/futex.h>)
#include <sys/futex.h>
#endif
#endif

#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
2 changes: 1 addition & 1 deletion include/tbb/tbb_machine.h
Original file line number Diff line number Diff line change
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__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is || __OpenBSD__ enough to build TBB on OpenBSD (and without this improvement the build fails)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test OpenBSD, I don't have access to the system. The reason I added this check is that OpenBSD supports futexes, and the other code in the guarded headers doesn't look system-specific.


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