Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Thread_Mutex Class Reference

ACE_Thread_Mutex wrapper (only valid for threads in the same process). More...

#include <Synch.h>

List of all members.

Public Methods

 ACE_Thread_Mutex (const ACE_TCHAR *name=0, ACE_mutexattr_t *attributes=0)
 Constructor. More...

 ~ACE_Thread_Mutex (void)
 Implicitly destroy the mutex. More...

int remove (void)
int acquire (void)
 Acquire lock ownership (wait on queue if necessary). More...

int acquire (ACE_Time_Value &tv)
int acquire (ACE_Time_Value *tv)
int tryacquire (void)
int release (void)
 Release lock and unblock a thread at head of queue. More...

int acquire_read (void)
int acquire_write (void)
int tryacquire_read (void)
int tryacquire_write (void)
int tryacquire_write_upgrade (void)
const ACE_thread_mutex_t & lock (void) const
 Return the underlying mutex. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...

ACE_thread_mutex_t lock_
 Mutex type that supports single-process locking efficiently. More...

int removed_
 Keeps track of whether <remove> has been called yet to avoid multiple <remove> calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling <remove> on the same object, which is a bad idea anyway... More...


Private Methods

void operator= (const ACE_Thread_Mutex &)
 ACE_Thread_Mutex (const ACE_Thread_Mutex &)

Friends

class ACE_Condition_Thread_Mutex


Detailed Description

ACE_Thread_Mutex wrapper (only valid for threads in the same process).

This implementation is optimized for locking threads that are in the same process. It maps to <CRITICAL_SECTION>s on NT and <ACE_mutex_t> with <type> set to <USYNC_THREAD> on UNIX. ACE_Thread_Mutex is recursive on some platforms (like Win32). However, on most platforms (like Solaris) it is not recursive. To be totally safe and portable, developers should use <ACE_Recursive_Thread_Mutex> when they need a recursive mutex.

Definition at line 1029 of file Synch.h.


Constructor & Destructor Documentation

ACE_Thread_Mutex::ACE_Thread_Mutex const ACE_TCHAR   name = 0,
ACE_mutexattr_t *    attributes = 0
 

Constructor.

Definition at line 836 of file Synch.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, LM_ERROR, and ACE_OS::thread_mutex_init.

00837   : removed_ (0)
00838 {
00839 //  ACE_TRACE ("ACE_Thread_Mutex::ACE_Thread_Mutex");
00840 
00841   if (ACE_OS::thread_mutex_init (&this->lock_,
00842                                  USYNC_THREAD,
00843                                  name,
00844                                  arg) != 0)
00845     ACE_ERROR ((LM_ERROR,
00846                 ACE_LIB_TEXT ("%p\n"),
00847                 ACE_LIB_TEXT ("ACE_Thread_Mutex::ACE_Thread_Mutex")));
00848 }

ACE_Thread_Mutex::~ACE_Thread_Mutex void   
 

Implicitly destroy the mutex.

Definition at line 830 of file Synch.cpp.

References remove.

00831 {
00832 // ACE_TRACE ("ACE_Thread_Mutex::~ACE_Thread_Mutex");
00833   this->remove ();
00834 }

ACE_Thread_Mutex::ACE_Thread_Mutex const ACE_Thread_Mutex &    [private]
 


Member Function Documentation

int ACE_Thread_Mutex::acquire ACE_Time_Value   tv
 

If <tv> == 0 the call <acquire()> directly. Otherwise, Block the thread until we acquire the mutex or until <tv> times out, in which case -1 is returned with <errno> == <ETIME>. Note that <*tv> is assumed to be in "absolute" rather than "relative" time. The value of <*tv> is updated upon return to show the actual (absolute) acquisition time.

int ACE_Thread_Mutex::acquire ACE_Time_Value   tv
 

Block the thread until we acquire the mutex or until <tv> times out, in which case -1 is returned with <errno> == <ETIME>. Note that <tv> is assumed to be in "absolute" rather than "relative" time. The value of <tv> is updated upon return to show the actual (absolute) acquisition time.

int ACE_Thread_Mutex::acquire void   
 

Acquire lock ownership (wait on queue if necessary).

Referenced by ACE_Token::ACE_Token_Queue_Entry::wait.

int ACE_Thread_Mutex::acquire_read void   
 

Acquire mutex ownership. This calls <acquire> and is only here to make the <ACE_Thread_Mutex> interface consistent with the other synchronization APIs.

int ACE_Thread_Mutex::acquire_write void   
 

Acquire mutex ownership. This calls <acquire> and is only here to make the <ACE_Thread_Mutex> interface consistent with the other synchronization APIs.

void ACE_Thread_Mutex::dump void    const
 

Dump the state of an object.

Definition at line 821 of file Synch.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, and LM_DEBUG.

Referenced by ACE_Barrier::dump, and ACE_Future_Rep::dump.

00822 {
00823 // ACE_TRACE ("ACE_Thread_Mutex::dump");
00824 
00825   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00826   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00827   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00828 }

const ACE_thread_mutex_t& ACE_Thread_Mutex::lock void    const
 

Return the underlying mutex.

void ACE_Thread_Mutex::operator= const ACE_Thread_Mutex &    [private]
 

int ACE_Thread_Mutex::release void   
 

Release lock and unblock a thread at head of queue.

Referenced by ACE_Token::ACE_Token_Queue_Entry::wait.

int ACE_Thread_Mutex::remove void   
 

Explicitly destroy the mutex. Note that only one thread should call this method since it doesn't protect against race conditions.

Referenced by ~ACE_Thread_Mutex.

int ACE_Thread_Mutex::tryacquire void   
 

Conditionally acquire lock (i.e., don't wait on queue). Returns -1 on failure. If we "failed" because someone else already had the lock, <errno> is set to <EBUSY>.

int ACE_Thread_Mutex::tryacquire_read void   
 

Conditionally acquire mutex (i.e., won't block). This calls <tryacquire> and is only here to make the <ACE_Thread_Mutex> interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, <errno> is set to <EBUSY>.

int ACE_Thread_Mutex::tryacquire_write void   
 

Conditionally acquire mutex (i.e., won't block). This calls <tryacquire> and is only here to make the <ACE_Thread_Mutex> interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, <errno> is set to <EBUSY>.

int ACE_Thread_Mutex::tryacquire_write_upgrade void   
 

This is only here to make the <ACE_Thread_Mutex> interface consistent with the other synchronization APIs. Assumes the caller has already acquired the mutex using one of the above calls, and returns 0 (success) always.


Friends And Related Function Documentation

friend class ACE_Condition_Thread_Mutex [friend]
 

Definition at line 1031 of file Synch.h.


Member Data Documentation

ACE_Thread_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 1126 of file Synch.h.

ACE_thread_mutex_t ACE_Thread_Mutex::lock_
 

Mutex type that supports single-process locking efficiently.

Definition at line 1130 of file Synch.h.

Referenced by ACE_Condition_Thread_Mutex::wait.

int ACE_Thread_Mutex::removed_
 

Keeps track of whether <remove> has been called yet to avoid multiple <remove> calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling <remove> on the same object, which is a bad idea anyway...

Definition at line 1137 of file Synch.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:57:41 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002