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

ACE_Condition_Thread_Mutex Class Reference

ACE_Condition variable wrapper written using ACE_Mutexes This allows threads to block until shared data changes state. A condition variable enables threads to atomically block and test the condition under the protection of a mutual exclu- sion lock (mutex) until the condition is satisfied. That is, the mutex must have been held by the thread before calling wait or signal on the condition. If the condition is false, a thread blocks on a condition variable and atomically releases the mutex that is waiting for the condition to change. If another thread changes the condition, it may wake up waiting threads by signaling the associated condition variable. The waiting threads, upon awakening, reacquire the mutex and re-evaluate the condition. More...

#include <Synch.h>

Collaboration diagram for ACE_Condition_Thread_Mutex:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Condition_Thread_Mutex (const ACE_Thread_Mutex &m, const ACE_TCHAR *name=0, void *arg=0)
 Initialize the condition variable. More...

 ACE_Condition_Thread_Mutex (const ACE_Thread_Mutex &m, ACE_Condition_Attributes &attributes, const ACE_TCHAR *name=0, void *arg=0)
 Initialize the condition variable. More...

 ~ACE_Condition_Thread_Mutex (void)
 Implicitly destroy the condition variable. More...

int remove (void)
int wait (const ACE_Time_Value *abstime)
int wait (void)
 Block on condition. More...

int wait (ACE_Thread_Mutex &mutex, const ACE_Time_Value *abstime=0)
int signal (void)
 Signal one waiting thread. More...

int broadcast (void)
 Signal *all* waiting threads. More...

ACE_Thread_Mutexmutex (void)
 Returns a reference to 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...


Protected Attributes

ACE_cond_t cond_
 Condition variable. More...

ACE_Thread_Mutexmutex_
 Reference to mutex lock. 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_Condition_Thread_Mutex &)
 ACE_Condition_Thread_Mutex (const ACE_Condition_Thread_Mutex &)

Detailed Description

ACE_Condition variable wrapper written using ACE_Mutexes This allows threads to block until shared data changes state. A condition variable enables threads to atomically block and test the condition under the protection of a mutual exclu- sion lock (mutex) until the condition is satisfied. That is, the mutex must have been held by the thread before calling wait or signal on the condition. If the condition is false, a thread blocks on a condition variable and atomically releases the mutex that is waiting for the condition to change. If another thread changes the condition, it may wake up waiting threads by signaling the associated condition variable. The waiting threads, upon awakening, reacquire the mutex and re-evaluate the condition.

This should be an instantiation of ACE_Condition but problems with compilers precludes this...

Definition at line 1250 of file Synch.h.


Constructor & Destructor Documentation

ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex const ACE_Thread_Mutex   m,
const ACE_TCHAR   name = 0,
void *    arg = 0
 

Initialize the condition variable.

Definition at line 588 of file Synch.cpp.

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

00591   : mutex_ ((ACE_Thread_Mutex &) m),
00592     removed_ (0)
00593 {
00594 #if defined (ACE_HAS_FSU_PTHREADS)
00595 //      Initialize FSU pthreads package.
00596 //      If called more than once, pthread_init does nothing
00597 //      and so does no harm.
00598    pthread_init ();
00599 #endif  /*  ACE_HAS_FSU_PTHREADS */
00600 
00601 // ACE_TRACE ("ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex");
00602   if (ACE_OS::cond_init (&this->cond_,
00603                          (short) USYNC_THREAD,
00604                          name,
00605                          arg) != 0)
00606     ACE_ERROR ((LM_ERROR,
00607                 ACE_LIB_TEXT ("%p\n"),
00608                 ACE_LIB_TEXT ("ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex")));
00609 }

ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex const ACE_Thread_Mutex   m,
ACE_Condition_Attributes   attributes,
const ACE_TCHAR   name = 0,
void *    arg = 0
 

Initialize the condition variable.

Definition at line 612 of file Synch.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, ACE_Condition_Attributes::attributes_, ACE_OS::cond_init, and LM_ERROR.

00616   : mutex_ ((ACE_Thread_Mutex &) m),
00617     removed_ (0)
00618 {
00619 #if defined (ACE_HAS_FSU_PTHREADS)
00620 //      Initialize FSU pthreads package.
00621 //      If called more than once, pthread_init does nothing
00622 //      and so does no harm.
00623    pthread_init ();
00624 #endif  /*  ACE_HAS_FSU_PTHREADS */
00625 
00626 // ACE_TRACE ("ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex");
00627   if (ACE_OS::cond_init (&this->cond_, attributes.attributes_,
00628                          name, arg) != 0)
00629     ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"),
00630                 ACE_LIB_TEXT ("ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex")));
00631 }

ACE_Condition_Thread_Mutex::~ACE_Condition_Thread_Mutex void   
 

Implicitly destroy the condition variable.

Definition at line 633 of file Synch.cpp.

References remove.

00634 {
00635 // ACE_TRACE ("ACE_Condition_Thread_Mutex::~ACE_Condition_Thread_Mutex");
00636   this->remove ();
00637 }

ACE_Condition_Thread_Mutex::ACE_Condition_Thread_Mutex const ACE_Condition_Thread_Mutex &    [private]
 


Member Function Documentation

int ACE_Condition_Thread_Mutex::broadcast void   
 

Signal *all* waiting threads.

Definition at line 675 of file Synch.cpp.

References ACE_OS::cond_broadcast.

Referenced by ACE_Thread_Manager::remove_thr, ACE_Future_Rep::set, and ACE_Barrier::wait.

00676 {
00677 // ACE_TRACE ("ACE_Condition_Thread_Mutex::broadcast");
00678   return ACE_OS::cond_broadcast (&this->cond_);
00679 }

void ACE_Condition_Thread_Mutex::dump void    const
 

Dump the state of an object.

Definition at line 574 of file Synch.cpp.

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

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

00575 {
00576 // ACE_TRACE ("ACE_Condition_Thread_Mutex::dump");
00577 
00578   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00579   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00580 #if defined (ACE_WIN32)
00581   ACE_DEBUG ((LM_DEBUG,
00582               ACE_LIB_TEXT ("waiters = %d\n"),
00583               this->cond_.waiters ()));
00584 #endif /* ACE_WIN32 */
00585   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00586 }

ACE_Thread_Mutex& ACE_Condition_Thread_Mutex::mutex void   
 

Returns a reference to the underlying mutex;.

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

int ACE_Condition_Thread_Mutex::remove void   
 

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

Referenced by ~ACE_Condition_Thread_Mutex.

int ACE_Condition_Thread_Mutex::signal void   
 

Signal one waiting thread.

Definition at line 668 of file Synch.cpp.

References ACE_OS::cond_signal.

00669 {
00670 // ACE_TRACE ("ACE_Condition_Thread_Mutex::signal");
00671   return ACE_OS::cond_signal (&this->cond_);
00672 }

int ACE_Condition_Thread_Mutex::wait ACE_Thread_Mutex   mutex,
const ACE_Time_Value   abstime = 0
 

Block on condition or until absolute time-of-day has passed. If abstime == 0 use "blocking" wait() semantics on the <mutex> passed as a parameter (this is useful if you need to store the <Condition> in shared memory). Else, if <abstime> != 0 and the call times out before the condition is signaled <wait> returns -1 and sets errno to ETIME.

Definition at line 651 of file Synch.cpp.

References ACE_OS::cond_timedwait, and ACE_Thread_Mutex::lock_.

00653 {
00654 // ACE_TRACE ("ACE_Condition_Thread_Mutex::wait");
00655   return ACE_OS::cond_timedwait (&this->cond_,
00656                                  &mutex.lock_,
00657                                  (ACE_Time_Value *) abstime);
00658 }

int ACE_Condition_Thread_Mutex::wait void   
 

Block on condition.

Definition at line 644 of file Synch.cpp.

References ACE_OS::cond_wait.

Referenced by wait.

00645 {
00646 // ACE_TRACE ("ACE_Condition_Thread_Mutex::wait");
00647   return ACE_OS::cond_wait (&this->cond_, &this->mutex_.lock_);
00648 }

int ACE_Condition_Thread_Mutex::wait const ACE_Time_Value   abstime
 

Block on condition, or until absolute time-of-day has passed. If abstime == 0 use "blocking" <wait> semantics. Else, if <abstime> != 0 and the call times out before the condition is signaled <wait> returns -1 and sets errno to ETIME.

Definition at line 661 of file Synch.cpp.

References wait.

Referenced by ACE_Future_Rep::operator T, ACE_Thread_Manager::wait, and ACE_Barrier::wait.

00662 {
00663 // ACE_TRACE ("ACE_Condition_Thread_Mutex::wait");
00664   return this->wait (this->mutex_, abstime);
00665 }


Member Data Documentation

ACE_Condition_Thread_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 1308 of file Synch.h.

ACE_cond_t ACE_Condition_Thread_Mutex::cond_ [protected]
 

Condition variable.

Definition at line 1312 of file Synch.h.

ACE_Thread_Mutex& ACE_Condition_Thread_Mutex::mutex_ [protected]
 

Reference to mutex lock.

Definition at line 1315 of file Synch.h.

int ACE_Condition_Thread_Mutex::removed_ [protected]
 

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 1322 of file Synch.h.


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