carb::thread::recursive_mutex
Defined in carb/thread/Mutex.h
-
class recursive_mutex : protected detail::BaseMutex<true>
A Carbonite implementation of std::recursive_mutex.
Note
Windows:
std::recursive_mutex
usesSRWLOCK
for Win 7+,CONDITION_VARIABLE
for Vista and the massiveCRITICAL_SECTION
for pre-Vista. Due to this, thestd::recursive_mutex
class is about 80 bytes. Since Carbonite supports Windows 10 and later,SRWLOCK
is used exclusively. This implementation is 16 bytes. This version that usesSRWLOCK
is significantly faster on Windows than the portable implementation used for the linux version.Note
Linux:
sizeof(std::recursive_mutex)
is 40 bytes on GLIBC 2.27, which is based on the size ofpthread_mutex_t
. The Carbonite implementation of recursive_mutex is 24 bytes and at least as performant asstd::recursive_mutex
in the contended case.Public Functions
-
recursive_mutex() noexcept = default
Constructor.
Note
Unlike
std::recursive_mutex
, this implementation can be declaredconstexpr
.
-
~recursive_mutex() = default
Destructor.
Warning
std::terminate()
is called if recursive_mutex is locked by a thread.
-
inline void lock()
Locks the recursive_mutex, blocking until it becomes available.
The calling thread must call unlock() at a later time to release the lock. There must be symmetrical calls to unlock() for each call to lock() or successful call to try_lock().
-
inline bool try_lock()
Attempts to immediately lock the recursive_mutex.
- Returns
true
if the recursive_mutex was available and the lock was taken by the calling thread (unlock() must be called from the calling thread at a later time to release the lock);false
if the recursive_mutex could not be locked by the calling thread. If the lock was already held by the calling thread,true
is always returned.
-
inline void unlock()
Unlocks the recursive_mutex.
Warning
std::terminate()
is called if the calling thread does not own the recursive_mutex.
-
inline bool is_current_thread_owner() const noexcept
Checks if the current thread owns the mutex.
Note
This is a non-standard Carbonite extension.
- Returns
true
if the current thread owns the mutex;false
otherwise.
-
recursive_mutex() noexcept = default