CMutex Class Reference
[Threads]

Search Toolkit Book for CMutex

#include <ncbimtx.hpp>

Inheritance diagram for CMutex:

Inheritance graph
[legend]
Collaboration diagram for CMutex:

Collaboration graph
[legend]
List of all members.

Detailed Description

CMutex --.

Mutex that allows nesting with runtime checks.

Allows for recursive locks by the same thread. Checks the mutex owner before unlocking. This mutex should be used when performance is less important than data protection. For faster performance see CFastMutex.

See also:
http://www.ncbi.nlm.nih.gov/books/bv.fcgi?rid=toolkit.section.ch_core.threads#ch_core.mutexes

Definition at line 715 of file ncbimtx.hpp.

Public Types

typedef CMutexGuard TReadLockGuard
 Define Read Lock Guard.
typedef CMutexGuard TWriteLockGuard
 Define Write Lock Guard.

Public Member Functions

 CMutex (void)
 Constructor.
 ~CMutex (void)
 Destructor.
 operator SSystemMutex & (void)
 Get SSystemMutex.
void Lock (void)
 Lock mutex.
bool TryLock (void)
 Try locking mutex.
void Unlock (void)
 Unlock mutex.

Private Member Functions

 CMutex (const CMutex &)
 Private copy constructor to disallow initialization.
CMutexoperator= (const CMutex &)
 Private assignment operator to disallow assignment.

Private Attributes

SSystemMutex m_Mutex
 System mutex.

Friends

class CRWLock
 Allow use of m_Mtx and m_Owner members directly.


Member Typedef Documentation

typedef CMutexGuard CMutex::TReadLockGuard
 

Define Read Lock Guard.

Definition at line 727 of file ncbimtx.hpp.

typedef CMutexGuard CMutex::TWriteLockGuard
 

Define Write Lock Guard.

Definition at line 730 of file ncbimtx.hpp.


Constructor & Destructor Documentation

CMutex::CMutex void   ) 
 

Constructor.

CMutex::~CMutex void   ) 
 

Destructor.

Report error if the mutex is locked.

CMutex::CMutex const CMutex  )  [private]
 

Private copy constructor to disallow initialization.


Member Function Documentation

void CMutex::Lock void   ) 
 

Lock mutex.

Operation:

  • If the mutex is unlocked, then acquire it for the calling thread.
  • If the mutex is acquired by this thread, then increase the lock counter (each call to Lock() must have corresponding call to Unlock() in the same thread).
  • If the mutex is acquired by another thread, then wait until it's unlocked, then act like a Lock() on an unlocked mutex.

Referenced by CAppJobDispatcher::Lock(), CRegistryFile::Lock(), CGBProject::Lock(), CObservable::Lock(), CSeqDBAtlas::ShowLayout(), CTimer::Start(), and CTimer::Time().

CMutex::operator SSystemMutex & void   ) 
 

Get SSystemMutex.

CMutex& CMutex::operator= const CMutex  )  [private]
 

Private assignment operator to disallow assignment.

bool CMutex::TryLock void   ) 
 

Try locking mutex.

Try to acquire the mutex.

Returns:
  • On success, return TRUE, and acquire the mutex just as the Lock() does.
  • If the mutex is already acquired by another thread, then return FALSE.
See also:
Lock()

Referenced by CAppJobDispatcher::OnEngineJobStateChanged(), and CRegistryFile::TryLock().

void CMutex::Unlock void   ) 
 

Unlock mutex.

Operation:

  • If the mutex is acquired by this thread, then decrease the lock counter.
  • If the lock counter becomes zero, then release the mutex completely.
  • Report error if the mutex is not locked or locked by another thread.

Referenced by CSeqDBAtlas::ShowLayout(), CTimer::Stop(), CTimer::Time(), CAppJobDispatcher::Unlock(), CRegistryFile::Unlock(), CGBProject::Unlock(), and CObservable::Unlock().


Friends And Related Function Documentation

friend class CRWLock [friend]
 

Allow use of m_Mtx and m_Owner members directly.

Definition at line 773 of file ncbimtx.hpp.


Member Data Documentation

SSystemMutex CMutex::m_Mutex [private]
 

System mutex.

Definition at line 765 of file ncbimtx.hpp.


The documentation for this class was generated from the following file:
Generated on Wed Dec 9 08:02:56 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Wed Dec 09 08:19:30 2009 by modify_doxy.py rev. 173732