Cross-Platform C++

ot
class RecursiveMutex

#include "ot/base/RecursiveMutex.h"

Variety of mutex that can be locked multiple times by the same thread without blocking. A mutex can be acquired (locked) by only one thread at a time. A RecursiveMutex can be locked multiple times by the same thread without blocking. It contains an internal usage count which is incremented by lock() and decremented by unlock(). When the internal usage count is decremented to zero the mutex is released and may be acquired by another thread.

While a thread 'owns' the mutex (i.e. has it locked), it can safely use the protected resource, which may be a variable, a region of memory or anything else, in the knowledge that no other thread will be accessing it. However, this only holds true if all threads obey the rules and acquire the mutex before attempting to access the protected resource. This is where the 'mutual' part comes in - all programs that access the resource must acquire the mutex first.

See also:
Mutex , FastMutex



Constructor/Destructor Summary
RecursiveMutex()
         Default constructor.

Method Summary
 bool isLocked()
         Tests if the mutex is currently owned by the current thread.
 void lock()
         Acquires the mutex.
 bool tryLock()
         Attempts to acquire the mutex without blocking.
 void unlock()
         Releases the mutex.

Typedefs

Lock

typedef AutoLock< RecursiveMutex > Lock

Constructor/Destructor Detail

RecursiveMutex

 RecursiveMutex()
Default constructor.


Method Detail

isLocked

bool isLocked()
Tests if the mutex is currently owned by the current thread.

Returns:
true if the current thread has the mutex locked; false otherwise

lock

void lock()
Acquires the mutex. If the current thread already owns the mutex then the lock count is incremented. In this case unlock() must be called an equal number of times before the mutex will become released.

If the mutex is currently held by another thread this call blocks and waits until the mutex becomes available.


tryLock

bool tryLock()
Attempts to acquire the mutex without blocking. This function differs from lock() because it returns immediately even if the mutex is held by another thread.

If the current thread already owns the mutex then the lock count is incremented. In this case unlock() must be called an equal number of times before the mutex will become released.

Returns:
true if the mutex was successfully acquired; false otherwise.
See also:
lock() , unlock()

unlock

void unlock()
Releases the mutex. unlock() must be called an equal number of times that lock() is called before the mutex is released and made available to another thread.

Exceptions:
IllegalMonitorStateException - if the current thread does not own the mutex (i.e. does not have it locked)


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements