summaryrefslogtreecommitdiffstats
path: root/core/os/semaphore.h
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2023-11-17 20:44:38 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2023-11-18 11:56:05 +0100
commitfe4850c0d0e8eed3fe851007c667206684aab0fc (patch)
treec71ad807d00a3ed83a8f73dd630b62ed76cca211 /core/os/semaphore.h
parentad72de508363ca8d10c6b148be44a02cdf12be13 (diff)
downloadredot-engine-fe4850c0d0e8eed3fe851007c667206684aab0fc.tar.gz
Use mingw-std-threads in MinGW builds
Diffstat (limited to 'core/os/semaphore.h')
-rw-r--r--core/os/semaphore.h16
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