ACE_Thread_Mutex Class Reference

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

#include <Thread_Mutex.h>

List of all members.

Public Member Functions

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

 ~ACE_Thread_Mutex (void)
 Implicitly destroy the mutex.

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

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.

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.

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


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

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

int removed_

Private Member Functions

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 s on NT and with set to 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 50 of file Thread_Mutex.h.


Constructor & Destructor Documentation

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

Constructor.

Definition at line 62 of file Thread_Mutex.cpp.

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

00063   : removed_ (0)
00064 {
00065 //  ACE_TRACE ("ACE_Thread_Mutex::ACE_Thread_Mutex");
00066 
00067   if (ACE_OS::thread_mutex_init (&this->lock_,
00068                                  0,
00069                                  name,
00070                                  arg) != 0)
00071     ACE_ERROR ((LM_ERROR,
00072                 ACE_LIB_TEXT ("%p\n"),
00073                 ACE_LIB_TEXT ("ACE_Thread_Mutex::ACE_Thread_Mutex")));
00074 }

ACE_Thread_Mutex::~ACE_Thread_Mutex void   ) 
 

Implicitly destroy the mutex.

Definition at line 56 of file Thread_Mutex.cpp.

References remove().

00057 {
00058 // ACE_TRACE ("ACE_Thread_Mutex::~ACE_Thread_Mutex");
00059   this->remove ();
00060 }

ACE_Thread_Mutex::ACE_Thread_Mutex const ACE_Thread_Mutex  )  [private]
 


Member Function Documentation

ACE_INLINE 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 times out, in which case -1 is returned with == . 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.

Definition at line 64 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_lock().

00065 {
00066   // ACE_TRACE ("ACE_Thread_Mutex::acquire");
00067   return ACE_OS::thread_mutex_lock (&this->lock_, tv);
00068 }

ACE_INLINE 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 == . 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.

Definition at line 57 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_lock().

00058 {
00059   // ACE_TRACE ("ACE_Thread_Mutex::acquire");
00060   return ACE_OS::thread_mutex_lock (&this->lock_, tv);
00061 }

ACE_INLINE int ACE_Thread_Mutex::acquire void   ) 
 

Acquire lock ownership (wait on queue if necessary).

Definition at line 50 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_lock().

Referenced by ACE_Token::ACE_Token_Queue_Entry::wait().

00051 {
00052 // ACE_TRACE ("ACE_Thread_Mutex::acquire");
00053   return ACE_OS::thread_mutex_lock (&this->lock_);
00054 }

ACE_INLINE int ACE_Thread_Mutex::acquire_read void   ) 
 

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

Definition at line 15 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_lock().

00016 {
00017 // ACE_TRACE ("ACE_Thread_Mutex::acquire_read");
00018   return ACE_OS::thread_mutex_lock (&this->lock_);
00019 }

ACE_INLINE int ACE_Thread_Mutex::acquire_write void   ) 
 

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

Definition at line 22 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_lock().

00023 {
00024 // ACE_TRACE ("ACE_Thread_Mutex::acquire_write");
00025   return ACE_OS::thread_mutex_lock (&this->lock_);
00026 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Thread_Mutex::dump void   )  const
 

Dump the state of an object.

Definition at line 45 of file Thread_Mutex.cpp.

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

Referenced by ACE_Barrier::dump().

00046 {
00047 #if defined (ACE_HAS_DUMP)
00048 // ACE_TRACE ("ACE_Thread_Mutex::dump");
00049 
00050   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00051   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00052   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00053 #endif /* ACE_HAS_DUMP */
00054 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE const ACE_thread_mutex_t & ACE_Thread_Mutex::lock void   )  const
 

Return the underlying mutex.

Definition at line 8 of file Thread_Mutex.inl.

00009 {
00010 // ACE_TRACE ("ACE_Thread_Mutex::lock");
00011   return this->lock_;
00012 }

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

ACE_INLINE int ACE_Thread_Mutex::release void   ) 
 

Release lock and unblock a thread at head of queue.

Definition at line 78 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_unlock().

Referenced by ACE_Token::ACE_Token_Queue_Entry::wait().

00079 {
00080 // ACE_TRACE ("ACE_Thread_Mutex::release");
00081   return ACE_OS::thread_mutex_unlock (&this->lock_);
00082 }

ACE_INLINE 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.

Definition at line 85 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_destroy().

Referenced by ~ACE_Thread_Mutex().

00086 {
00087 // ACE_TRACE ("ACE_Thread_Mutex::remove");
00088   int result = 0;
00089   if (this->removed_ == 0)
00090     {
00091       this->removed_ = 1;
00092       result = ACE_OS::thread_mutex_destroy (&this->lock_);
00093     }
00094   return result;
00095 }

ACE_INLINE 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, is set to .

Definition at line 71 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_trylock().

00072 {
00073 // ACE_TRACE ("ACE_Thread_Mutex::tryacquire");
00074   return ACE_OS::thread_mutex_trylock (&this->lock_);
00075 }

ACE_INLINE int ACE_Thread_Mutex::tryacquire_read void   ) 
 

Conditionally acquire mutex (i.e., won't block). This calls 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, is set to .

Definition at line 29 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_trylock().

00030 {
00031 // ACE_TRACE ("ACE_Thread_Mutex::tryacquire_read");
00032   return ACE_OS::thread_mutex_trylock (&this->lock_);
00033 }

ACE_INLINE int ACE_Thread_Mutex::tryacquire_write void   ) 
 

Conditionally acquire mutex (i.e., won't block). This calls 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, is set to .

Definition at line 36 of file Thread_Mutex.inl.

References ACE_OS::thread_mutex_trylock().

00037 {
00038 // ACE_TRACE ("ACE_Thread_Mutex::tryacquire_write");
00039   return ACE_OS::thread_mutex_trylock (&this->lock_);
00040 }

ACE_INLINE 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.

Definition at line 43 of file Thread_Mutex.inl.

00044 {
00045 // ACE_TRACE ("ACE_Thread_Mutex::tryacquire_write_upgrade");
00046   return 0;
00047 }


Friends And Related Function Documentation

friend class ACE_Condition_Thread_Mutex [friend]
 

Definition at line 52 of file Thread_Mutex.h.


Member Data Documentation

ACE_Thread_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 147 of file Thread_Mutex.h.

ACE_thread_mutex_t ACE_Thread_Mutex::lock_
 

Mutex type that supports single-process locking efficiently.

Definition at line 151 of file Thread_Mutex.h.

Referenced by ACE_Condition_Thread_Mutex::wait().

int ACE_Thread_Mutex::removed_
 

Keeps track of whether has been called yet to avoid multiple 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 on the same object, which is a bad idea anyway...

Definition at line 158 of file Thread_Mutex.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:31:03 2006 for ACE by doxygen 1.3.6