Skip to content
New issue

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

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

Already on GitHub? # to your account

Portability fixes for Cygwin and Clang on MSYS #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# -------------------------------------------------------------------

cmake_minimum_required(VERSION 3.14)
project(PARLAY VERSION 2.2.3
project(PARLAY VERSION 2.2.4
DESCRIPTION "A collection of parallel algorithms and other support for parallelism in C++"
LANGUAGES CXX)

Expand Down
15 changes: 9 additions & 6 deletions include/parlay/internal/atomic_wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The strategy is chosen this way, by platform:
#define __ABI
#endif

#if defined(__APPLE__) || defined(__linux__)
#if defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__)

#include <unistd.h>
#include <sched.h>
Expand Down Expand Up @@ -137,7 +137,7 @@ The strategy is chosen this way, by platform:
#define __NO_CONDVAR
#define __NO_TABLE


#ifndef NOMINMAX
#define PARLAY_DEFINED_NOMINMAX
#define NOMINMAX
Expand All @@ -146,18 +146,21 @@ The strategy is chosen this way, by platform:
#ifdef PARLAY_DEFINED_NOMINMAX
#undef NOMINMAX
#endif

#define __YIELD() Sleep(0)
#define __SLEEP(x) Sleep(x)
#define __YIELD_PROCESSOR() YieldProcessor()

#if !defined(__clang__)
#include <intrin.h>
template <class _Tp>
auto __atomic_load_n(_Tp const* a, int) -> typename std::remove_reference<decltype(*a)>::type {
auto const t = *a;
_ReadWriteBarrier();
return t;
}
#endif

#define __builtin_expect(e, v) (e)

#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8) && !defined(__NO_FUTEX)
Expand Down Expand Up @@ -255,7 +258,7 @@ The strategy is chosen this way, by platform:
#elif defined(__FUTEX)

template <class _Tp, typename std::enable_if<!__type_used_directly(_Tp), int>::type = 1>
void __cxx_atomic_notify_all(_Tp const* ptr) {
void __cxx_atomic_notify_all([[maybe_unused]] _Tp const* ptr) {
#if defined(__TABLE)
auto * const c = __contention(ptr);
__atomic_fetch_add(&c->version, 1, __ATOMIC_RELAXED);
Expand Down Expand Up @@ -326,9 +329,9 @@ The strategy is chosen this way, by platform:
__cxx_atomic_try_wait_slow_fallback(ptr, val, order);
}
template <class _Tp>
__ABI void __cxx_atomic_notify_one(_Tp const* ptr) { }
__ABI void __cxx_atomic_notify_one([[maybe_unused]] _Tp const* ptr) { }
template <class _Tp>
__ABI void __cxx_atomic_notify_all(_Tp const* ptr) { }
__ABI void __cxx_atomic_notify_all([[maybe_unused]] _Tp const* ptr) { }

#endif // __FUTEX || __CONDVAR

Expand Down
5 changes: 4 additions & 1 deletion include/parlay/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdlib>

#include <iostream>
#include <utility>

namespace parlay {

Expand Down Expand Up @@ -76,13 +77,15 @@ namespace parlay {
#endif


#if defined(__cplusplus) && __cplusplus >= 202002L
#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(likely) && __has_cpp_attribute(unlikely)
#define PARLAY_LIKELY [[likely]]
#define PARLAY_UNLIKELY [[unlikely]]
#else
#define PARLAY_LIKELY
#define PARLAY_UNLIKELY
#endif
#endif

// Check for exceptions. The standard suggests __cpp_exceptions. Clang/GCC defined __EXCEPTIONS.
// MSVC disables them with _HAS_EXCEPTIONS=0. Might not cover obscure compilers/STLs.
Expand Down