summaryrefslogtreecommitdiffstats
path: root/core/os/mutex.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-01-18 09:33:52 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-01-18 09:33:52 +0100
commitfa81059b9d5c763c4775708d4832bf8bfc1dda80 (patch)
tree8acc89e6e12558fe003a07fe4acd02a9bba7b3e3 /core/os/mutex.h
parentb5dcb5f58aec77f8e282ff134f279c7bc7467e8e (diff)
parentbd70b8e1f643dbf7252be9bc367e0de0f82d722d (diff)
downloadredot-engine-fa81059b9d5c763c4775708d4832bf8bfc1dda80.tar.gz
Merge pull request #85939 from adamscott/single-threaded-godot-4
Add `THREADS_ENABLED` macro in order to compile Godot to run on the main thread
Diffstat (limited to 'core/os/mutex.h')
-rw-r--r--core/os/mutex.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/core/os/mutex.h b/core/os/mutex.h
index 03af48ca7c..69f494d9cd 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -43,6 +43,8 @@
#define THREADING_NAMESPACE std
#endif
+#ifdef THREADS_ENABLED
+
template <class MutexT>
class MutexLock;
@@ -125,8 +127,8 @@ class MutexLock {
THREADING_NAMESPACE::unique_lock<typename MutexT::StdMutexType> lock;
public:
- _ALWAYS_INLINE_ explicit MutexLock(const MutexT &p_mutex) :
- lock(p_mutex.mutex){};
+ explicit MutexLock(const MutexT &p_mutex) :
+ lock(p_mutex.mutex) {}
};
// This specialization is needed so manual locking and MutexLock can be used
@@ -155,4 +157,38 @@ extern template class MutexImpl<THREADING_NAMESPACE::mutex>;
extern template class MutexLock<MutexImpl<THREADING_NAMESPACE::recursive_mutex>>;
extern template class MutexLock<MutexImpl<THREADING_NAMESPACE::mutex>>;
+#else // No threads.
+
+class MutexImpl {
+ mutable THREADING_NAMESPACE::mutex mutex;
+
+public:
+ void lock() const {}
+ void unlock() const {}
+ bool try_lock() const { return true; }
+};
+
+template <int Tag>
+class SafeBinaryMutex : public MutexImpl {
+ static thread_local uint32_t count;
+};
+
+template <class MutexT>
+class MutexLock {
+public:
+ MutexLock(const MutexT &p_mutex) {}
+};
+
+template <int Tag>
+class MutexLock<SafeBinaryMutex<Tag>> {
+public:
+ MutexLock(const SafeBinaryMutex<Tag> &p_mutex) {}
+ ~MutexLock() {}
+};
+
+using Mutex = MutexImpl;
+using BinaryMutex = MutexImpl;
+
+#endif // THREADS_ENABLED
+
#endif // MUTEX_H