00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file CSD_TP_Synch_Helper.h 00006 * 00007 * $Id: CSD_TP_Synch_Helper.h 80158 2007-12-02 16:12:30Z sowayaa $ 00008 * 00009 * @author Tim Bradley <bradley_t@ociweb.com> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_CSD_TP_SYNCH_HELPER_H 00014 #define TAO_CSD_TP_SYNCH_HELPER_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/CSD_ThreadPool/CSD_TP_Export.h" 00019 #include "tao/Condition.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/Synch.h" 00026 00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 namespace TAO 00030 { 00031 namespace CSD 00032 { 00033 00034 /** 00035 * @class TP_Synch_Helper 00036 * 00037 * @brief Helper class for synchronous requests to block the requesting 00038 * thread until the appropriate time (when it will be un-blocked). 00039 * 00040 * TBD - Description here 00041 * 00042 */ 00043 class TAO_CSD_TP_Export TP_Synch_Helper 00044 { 00045 public: 00046 00047 /// Constructor. Sets initial state to PENDING. 00048 TP_Synch_Helper(); 00049 00050 /// Destructor. 00051 ~TP_Synch_Helper(); 00052 00053 /// Returns true if the helper state is DISPATCHED, and false if 00054 /// the helper state is CANCELLED. However, if the helper state 00055 /// is PENDING, then this method will block the calling thread 00056 /// until the state changes to something other than PENDING 00057 /// (ie, DISPATCHED or CANCELLED). 00058 bool wait_while_pending(); 00059 00060 /// Change the state of this helper to DISPATCHED, which will cause 00061 /// wait_while_pending() to unblock. 00062 void dispatched(); 00063 00064 /// Change the state of this helper to CANCELLED, which will cause 00065 /// wait_while_pending() to unblock. 00066 void cancelled(); 00067 00068 00069 private: 00070 00071 /// Enumeration Type for all possible states of this helper object. 00072 enum HelperState 00073 { 00074 PENDING, 00075 DISPATCHED, 00076 CANCELLED 00077 }; 00078 00079 /// Thread lock type 00080 typedef TAO_SYNCH_MUTEX LockType; 00081 00082 /// Thread guard type 00083 typedef ACE_Guard<LockType> GuardType; 00084 00085 /// Thread condition type 00086 typedef TAO_Condition<LockType> ConditionType; 00087 00088 /// Lock used to protect the state and condition. 00089 LockType lock_; 00090 00091 /// Used to denote the state of the request dispatching. 00092 HelperState state_; 00093 00094 /// The condition used to block the calling thread until the 00095 /// state is something other than the PENDING state. 00096 ConditionType condition_; 00097 }; 00098 00099 } 00100 } 00101 00102 TAO_END_VERSIONED_NAMESPACE_DECL 00103 00104 #if defined (__ACE_INLINE__) 00105 # include "tao/CSD_ThreadPool/CSD_TP_Synch_Helper.inl" 00106 #endif /* __ACE_INLINE__ */ 00107 00108 #include /**/ "ace/post.h" 00109 00110 #endif /* TAO_CSD_TP_SYNCH_HELPER_H */