diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-11-21 15:44:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-21 15:44:18 +0100 |
commit | c2f8fb301537a5d688d201178985963282b4f9c3 (patch) | |
tree | 6e21f7954af3ef36854f53830519c6b6be8c689f /core/os/semaphore.h | |
parent | fa259a77cd9ea725f22ccfd52d5c228e10358e1d (diff) | |
parent | fe4850c0d0e8eed3fe851007c667206684aab0fc (diff) | |
download | redot-engine-c2f8fb301537a5d688d201178985963282b4f9c3.tar.gz |
Merge pull request #85039 from RandomShaper/mingwthreads
Use mingw-std-threads in MinGW builds
Diffstat (limited to 'core/os/semaphore.h')
-rw-r--r-- | core/os/semaphore.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 66dfb3ee02..8bb1529bbd 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -37,13 +37,21 @@ #include "core/error/error_macros.h" #endif +#ifdef MINGW_ENABLED +#define MINGW_STDTHREAD_REDUNDANCY_WARNING +#include "thirdparty/mingw-std-threads/mingw.condition_variable.h" +#include "thirdparty/mingw-std-threads/mingw.mutex.h" +#define THREADING_NAMESPACE mingw_stdthread +#else #include <condition_variable> #include <mutex> +#define THREADING_NAMESPACE std +#endif class Semaphore { private: - mutable std::mutex mutex; - mutable std::condition_variable condition; + mutable THREADING_NAMESPACE::mutex mutex; + mutable THREADING_NAMESPACE::condition_variable condition; mutable uint32_t count = 0; // Initialized as locked. #ifdef DEBUG_ENABLED mutable uint32_t awaiters = 0; @@ -57,7 +65,7 @@ public: } _ALWAYS_INLINE_ void wait() const { - std::unique_lock lock(mutex); + THREADING_NAMESPACE::unique_lock lock(mutex); #ifdef DEBUG_ENABLED ++awaiters; #endif @@ -116,7 +124,7 @@ public: "A Semaphore object is being destroyed while one or more threads are still waiting on it.\n" "Please call post() on it as necessary to prevent such a situation and so ensure correct cleanup."); // And now, the hacky countermeasure (i.e., leak the condition variable). - new (&condition) std::condition_variable(); + new (&condition) THREADING_NAMESPACE::condition_variable(); } } #endif |