Reimplement Mutex with C++'s <mutex>
Main: - It's now implemented thanks to `<mutex>`. No more platform-specific implementations. - `BinaryMutex` (non-recursive) is added, as an alternative for special cases. - Doesn't need allocation/deallocation anymore. It can live in the stack and be part of other classes. - Because of that, it's methods are now `const` and the inner mutex is `mutable` so it can be easily used in `const` contexts. - A no-op implementation is provided if `NO_THREADS` is defined. No more need to add `#ifdef NO_THREADS` just for this. - `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`. - Thread-safe utilities are therefore simpler now. Misc.: - `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same. - Every case of lock, do-something, unlock is replaced by `MutexLock` (complex cases where it's not straightfoward are kept as as explicit lock and unlock). - `ShaderRD` contained an `std::mutex`, which has been replaced by `Mutex`.
This commit is contained in:
@ -57,7 +57,7 @@
|
||||
virtual RID m_type##_create() { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, &ret); \
|
||||
@ -65,7 +65,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(); \
|
||||
@ -88,7 +87,7 @@
|
||||
virtual RID m_type##_create(m_arg1 p1) { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, &ret); \
|
||||
@ -96,7 +95,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(p1); \
|
||||
@ -119,7 +117,7 @@
|
||||
virtual RID m_type##_create(m_arg1 p1, m_arg2 p2) { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, &ret); \
|
||||
@ -127,7 +125,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(p1, p2); \
|
||||
@ -150,7 +147,7 @@
|
||||
virtual RID m_type##_create(m_arg1 p1, m_arg2 p2, m_arg3 p3) { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, &ret); \
|
||||
@ -158,7 +155,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(p1, p2, p3); \
|
||||
@ -181,7 +177,7 @@
|
||||
virtual RID m_type##_create(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4) { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, p4, &ret); \
|
||||
@ -189,7 +185,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(p1, p2, p3, p4); \
|
||||
@ -213,7 +208,7 @@
|
||||
virtual RID m_type##_create(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5) { \
|
||||
if (Thread::get_caller_id() != server_thread) { \
|
||||
RID rid; \
|
||||
alloc_mutex->lock(); \
|
||||
MutexLock lock(alloc_mutex); \
|
||||
if (m_type##_id_pool.size() == 0) { \
|
||||
int ret; \
|
||||
command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, p4, p5, &ret); \
|
||||
@ -221,7 +216,6 @@
|
||||
} \
|
||||
rid = m_type##_id_pool.front()->get(); \
|
||||
m_type##_id_pool.pop_front(); \
|
||||
alloc_mutex->unlock(); \
|
||||
return rid; \
|
||||
} else { \
|
||||
return server_name->m_type##_create(p1, p2, p3, p4, p5); \
|
||||
|
||||
Reference in New Issue
Block a user