From 96f113c40d4934a98aed30a64851feec891a688a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 May 2022 10:33:34 +0200 Subject: Use our own implementation of C++14 threads on MinGW --- libbuild2/types.hxx | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'libbuild2/types.hxx') diff --git a/libbuild2/types.hxx b/libbuild2/types.hxx index cd6fdd8..c260aeb 100644 --- a/libbuild2/types.hxx +++ b/libbuild2/types.hxx @@ -29,14 +29,22 @@ #include // hash, function, reference_wrapper #include -#include #include -#include -#include -#include -#if defined(__cpp_lib_shared_mutex) || defined(__cpp_lib_shared_timed_mutex) -# include +#ifndef LIBBUTL_MINGW_STDTHREAD +# include +# include +# include + +# include +# if defined(__cpp_lib_shared_mutex) || defined(__cpp_lib_shared_timed_mutex) +# include +# endif +#else +# include +# include +# include +# include #endif #include // ios_base::failure @@ -189,20 +197,27 @@ namespace build2 } #endif +#ifndef LIBBUTL_MINGW_STDTHREAD using std::mutex; using mlock = std::unique_lock; using std::condition_variable; -#if defined(__cpp_lib_shared_mutex) + using std::defer_lock; + using std::adopt_lock; + + using std::thread; + namespace this_thread = std::this_thread; + +# if defined(__cpp_lib_shared_mutex) using shared_mutex = std::shared_mutex; using ulock = std::unique_lock; using slock = std::shared_lock; -#elif defined(__cpp_lib_shared_timed_mutex) +# 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 +# else // Because we have this fallback, we need to be careful not to create // multiple shared locks in the same thread. // @@ -217,13 +232,23 @@ namespace build2 using ulock = std::unique_lock; using slock = ulock; -#endif +# endif +#else // LIBBUTL_MINGW_STDTHREAD + using mingw_stdthread::mutex; + using mlock = mingw_stdthread::unique_lock; - using std::defer_lock; - using std::adopt_lock; + using mingw_stdthread::condition_variable; - using std::thread; - namespace this_thread = std::this_thread; + using mingw_stdthread::defer_lock; + using mingw_stdthread::adopt_lock; + + using mingw_stdthread::thread; + namespace this_thread = mingw_stdthread::this_thread; + + using shared_mutex = mingw_stdthread::shared_mutex; + using ulock = mingw_stdthread::unique_lock; + using slock = mingw_stdthread::shared_lock; +#endif // Global, MT-safe information cache. Normally used for caching information // (versions, target triplets, search paths, etc) extracted from other -- cgit v1.1