Condition.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Condition.h
00006  *
00007  *  Condition.h,v 1.12 2006/03/10 07:19:05 jtc Exp
00008  *
00009  *  @author From ACE to TAO by Balachandran Natarajan <bala@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_CONDITION_H
00014 #define TAO_CONDITION_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "tao/orbconf.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/Condition_T.h"
00025 #include "ace/Global_Macros.h"
00026 
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028 class ACE_Time_Value;
00029 ACE_END_VERSIONED_NAMESPACE_DECL
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 /**
00034  * @class TAO_Condition
00035  *
00036  * @brief Same as to the ACE_Condition variable wrapper
00037  *
00038  * This class differs from ACE_Condition in that it uses a
00039  * TAO_SYNCH_CONDITION instead of ACE_cond_t  under the hood to
00040  * provide blocking.
00041  */
00042 template <class MUTEX>
00043 class TAO_Condition
00044 {
00045 public:
00046 
00047   /// Useful typedef
00048   typedef MUTEX LOCK;
00049 
00050   // = Initialiation and termination methods.
00051   /// Initialize the condition variable.
00052   TAO_Condition (MUTEX &m);
00053 
00054   /// A default constructor. Since no lock is provided by the user,
00055   /// one will be created internally.
00056   TAO_Condition (void);
00057 
00058   /// Implicitly destroy the condition variable.
00059   ~TAO_Condition (void);
00060 
00061   // = Lock accessors.
00062   /**
00063    * Block on condition, or until absolute time-of-day has passed.  If
00064    * abstime == 0 use "blocking" <wait> semantics.  Else, if <abstime>
00065    * != 0 and the call times out before the condition is signaled
00066    * <wait> returns -1 and sets errno to ETIME.
00067    */
00068   int wait (const ACE_Time_Value *abstime);
00069 
00070   /// Block on condition.
00071   int wait (void);
00072 
00073   /**
00074    * Block on condition or until absolute time-of-day has passed.  If
00075    * abstime == 0 use "blocking" wait() semantics on the <mutex>
00076    * passed as a parameter (this is useful if you need to store the
00077    * <Condition> in shared memory).  Else, if <abstime> != 0 and the
00078    * call times out before the condition is signaled <wait> returns -1
00079    * and sets errno to ETIME.
00080    */
00081   int wait (MUTEX &mutex, const ACE_Time_Value *abstime = 0);
00082 
00083   /// Signal one waiting thread.
00084   int signal (void);
00085 
00086   /// Signal *all* waiting threads.
00087   int broadcast (void);
00088 
00089   // = Utility methods.
00090   /// Explicitly destroy the condition variable.
00091   int remove (void);
00092 
00093   /// Returns a reference to the underlying mutex_;
00094   MUTEX *mutex (void);
00095 
00096 private:
00097 
00098   /// Reference to mutex lock.
00099   MUTEX *mutex_;
00100 
00101   /// A flag to indicate whether the lock needs to be deleted.
00102   int delete_lock_;
00103 
00104   /// Condition variable.
00105   TAO_SYNCH_CONDITION *cond_;
00106 
00107   // = Prevent assignment and initialization.
00108   ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Condition<MUTEX> &))
00109   ACE_UNIMPLEMENTED_FUNC (TAO_Condition (const TAO_Condition<MUTEX> &))
00110 };
00111 
00112 TAO_END_VERSIONED_NAMESPACE_DECL
00113 
00114 #if defined (__ACE_INLINE__)
00115 #include "tao/Condition.inl"
00116 #endif /* __ACE_INLINE__ */
00117 
00118 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00119 #include "tao/Condition.cpp"
00120 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00121 
00122 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00123 #pragma implementation ("Condition.cpp")
00124 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00125 
00126 #include /**/ "ace/post.h"
00127 #endif /*TAO_CONDITION_H*/

Generated on Thu Nov 9 11:54:09 2006 for TAO by doxygen 1.3.6