aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-01 17:01:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:41 +0200
commit601ffbd700e7c11a101215d641ea09d0181d4771 (patch)
treef8d45e1b464bcadb4337f0646ccad868dbf484ce
parente3e597180487328a54721e2afb95e33ed853d586 (diff)
Fallback to normal mutex if shared_mutex not available
As is the case on MacOS prior to 10.12.
-rw-r--r--build2/types23
1 files changed, 17 insertions, 6 deletions
diff --git a/build2/types b/build2/types
index 7f39274..b9f3ce9 100644
--- a/build2/types
+++ b/build2/types
@@ -20,8 +20,11 @@
#include <mutex>
#include <future>
+
#include <butl/ft/shared_mutex>
-#include <shared_mutex>
+#if defined(__cpp_lib_shared_mutex) || defined(__cpp_lib_shared_timed_mutex)
+# include <shared_mutex>
+#endif
#include <ios> // ios_base::failure
#include <exception> // 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<shared_mutex>;
+ using slock = std::shared_lock<shared_mutex>;
+#elif defined(__cpp_lib_shared_timed_mutex)
using shared_mutex = std::shared_timed_mutex;
+ using ulock = std::unique_lock<shared_mutex>;
+ using slock = std::shared_lock<shared_mutex>;
+#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<shared_mutex>;
+ using slock = ulock;
#endif
- using slock = std::shared_lock<shared_mutex>;
- using ulock = std::unique_lock<shared_mutex>;
-
// Exceptions.
//
// While <exception> is included, there is no using for std::exception --