From ea2b4fb4935627e4dea48f193eeb0019155a3abe Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 May 2022 09:48:08 +0200 Subject: Use our own implementation of C++14 threads on MinGW --- libbutl/builtin.hxx | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'libbutl/builtin.hxx') diff --git a/libbutl/builtin.hxx b/libbutl/builtin.hxx index 2398c84..b8546be 100644 --- a/libbutl/builtin.hxx +++ b/libbutl/builtin.hxx @@ -4,17 +4,24 @@ #pragma once #include -#include #include #include -#include #include #include // unique_ptr #include // size_t #include // move() #include // uint8_t #include -#include + +#ifndef LIBBUTL_MINGW_STDTHREAD +# include +# include +# include +#else +# include +# include +# include +#endif #include #include @@ -56,12 +63,26 @@ namespace butl ~builtin () {if (state_ != nullptr) state_->thread.join ();} public: +#ifndef LIBBUTL_MINGW_STDTHREAD + using mutex_type = std::mutex; + using condition_variable_type = std::condition_variable; + using thread_type = std::thread; + + using unique_lock = std::unique_lock; +#else + using mutex_type = mingw_stdthread::mutex; + using condition_variable_type = mingw_stdthread::condition_variable; + using thread_type = mingw_stdthread::thread; + + using unique_lock = mingw_stdthread::unique_lock; +#endif + struct async_state { bool finished = false; - std::mutex mutex; - std::condition_variable condv; - std::thread thread; + mutex_type mutex; + condition_variable_type condv; + thread_type thread; // Note that we can't use std::function as an argument type to get rid // of the template since std::function can only be instantiated with a -- cgit v1.1