Add THREADS_ENABLED macro in order to compile Godot to run on the main thread

This commit is contained in:
Adam Scott
2023-12-01 13:39:09 -05:00
parent 107f2961cc
commit bd70b8e1f6
33 changed files with 447 additions and 72 deletions

View File

@ -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