-
Notifications
You must be signed in to change notification settings - Fork 59
class recursive_mutex
徐辰 edited this page Apr 8, 2014
·
3 revisions
-
Member functions
recursive_mutex()
-
recursive_mutex( const recursive_mutex& ) = delete
Constructs the mutex. The mutex is in unlocked state after the call.
Copy constructor is deleted. -
void lock()
Locks the mutex. If another fiber has already locked the mutex, a call tolock
will block execution until the lock is acquired.
A fiber may calllock
on a recursive mutex repeatedly. Ownership will only be released after the fiber makes a matching number of calls tounlock
. -
bool try_lock()
Tries to lock the mutex. Returns immediately. On successful lock acquisition returnstrue
, otherwise returnsfalse
.
Iftry_lock
is called by a fiber that already owns the mutex, it always returnstrue
.
A fiber may calltry_lock
on a recursive mutex repeatedly. Successful calls totry_lock
increment the ownership count: the mutex will only be released after the fiber makes a matching number of calls tounlock
. -
void unlock()
Unlocks the mutex if its level of ownership is 1 (there was exactly one more call tolock()
than there were calls tounlock()
made by this fiber), reduces the level of ownership by 1 otherwise.
The mutex must be locked by the current fiber of execution, otherwise anoperation_not_permitted
error condition may be thrown.