[Core] Allow locking/unlocking of MutexLock

This commit is contained in:
A Thousand Ships
2024-06-29 13:01:01 +02:00
parent e53dc80f2f
commit 723f5500f4
4 changed files with 59 additions and 26 deletions

View File

@ -72,7 +72,7 @@ public:
template <typename MutexT>
class MutexLock {
THREADING_NAMESPACE::unique_lock<typename MutexT::StdMutexType> lock;
mutable THREADING_NAMESPACE::unique_lock<typename MutexT::StdMutexType> lock;
public:
explicit MutexLock(const MutexT &p_mutex) :
@ -82,8 +82,18 @@ public:
template <typename T = MutexT>
_ALWAYS_INLINE_ THREADING_NAMESPACE::unique_lock<THREADING_NAMESPACE::mutex> &_get_lock(
typename std::enable_if<std::is_same<T, THREADING_NAMESPACE::mutex>::value> * = nullptr) const {
return const_cast<THREADING_NAMESPACE::unique_lock<THREADING_NAMESPACE::mutex> &>(lock);
return lock;
}
_ALWAYS_INLINE_ void temp_relock() const {
lock.lock();
}
_ALWAYS_INLINE_ void temp_unlock() const {
lock.unlock();
}
// TODO: Implement a `try_temp_relock` if needed (will also need a dummy method below).
};
using Mutex = MutexImpl<THREADING_NAMESPACE::recursive_mutex>; // Recursive, for general use
@ -109,6 +119,9 @@ template <typename MutexT>
class MutexLock {
public:
MutexLock(const MutexT &p_mutex) {}
void temp_relock() const {}
void temp_unlock() const {}
};
using Mutex = MutexImpl;