From 601ffbd700e7c11a101215d641ea09d0181d4771 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 1 Feb 2017 17:01:25 +0200 Subject: Fallback to normal mutex if shared_mutex not available As is the case on MacOS prior to 10.12. --- build2/types | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'build2/types') diff --git a/build2/types b/build2/types index 7f39274..b9f3ce9 100644 --- a/build2/types +++ b/build2/types @@ -20,8 +20,11 @@ #include #include + #include -#include +#if defined(__cpp_lib_shared_mutex) || defined(__cpp_lib_shared_timed_mutex) +# include +#endif #include // ios_base::failure #include // exception @@ -77,15 +80,23 @@ namespace build2 // using std::future; -#ifdef __cpp_lib_shared_mutex +#if defined(__cpp_lib_shared_mutex) using shared_mutex = std::shared_mutex; -#else + using ulock = std::unique_lock; + using slock = std::shared_lock; +#elif defined(__cpp_lib_shared_timed_mutex) using shared_mutex = std::shared_timed_mutex; + using ulock = std::unique_lock; + using slock = std::shared_lock; +#else + // Because we have this fallback, we need to be careful not to create + // multiple shared locks in the same thread. + // + using shared_mutex = std::mutex; + using ulock = std::unique_lock; + using slock = ulock; #endif - using slock = std::shared_lock; - using ulock = std::unique_lock; - // Exceptions. // // While is included, there is no using for std::exception -- -- cgit v1.1