00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_DCPS_WAITSET_H 00009 #define OPENDDS_DCPS_WAITSET_H 00010 00011 #include "dds/DdsDcpsInfrastructureC.h" 00012 00013 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00014 #pragma once 00015 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00016 00017 #include "dds/DCPS/LocalObject.h" 00018 #include "dds/DCPS/Definitions.h" 00019 #include "dds/DCPS/PoolAllocator.h" 00020 00021 #include "ace/Thread_Mutex.h" 00022 #include "ace/Condition_Recursive_Thread_Mutex.h" 00023 #include "ace/Atomic_Op.h" 00024 00025 namespace OpenDDS { 00026 namespace DCPS { 00027 00028 class ConditionImpl; 00029 00030 } // namespace DCPS 00031 } // namespace OpenDDS 00032 00033 namespace DDS { 00034 00035 class WaitSet; 00036 typedef WaitSet* WaitSet_ptr; 00037 00038 typedef TAO_Objref_Var_T<WaitSet> WaitSet_var; 00039 00040 class OpenDDS_Dcps_Export WaitSet 00041 : public virtual OpenDDS::DCPS::LocalObject<WaitSetInterf> { 00042 public: 00043 typedef WaitSet_ptr _ptr_type; 00044 typedef WaitSet_var _var_type; 00045 00046 WaitSet() 00047 : lock_(), 00048 cond_(lock_) 00049 {} 00050 00051 virtual ~WaitSet() {} 00052 00053 ReturnCode_t wait(ConditionSeq& active_conditions, 00054 const Duration_t& timeout); 00055 00056 ReturnCode_t attach_condition(Condition_ptr cond); 00057 00058 ReturnCode_t detach_condition(Condition_ptr cond); 00059 00060 ReturnCode_t get_conditions(ConditionSeq& attached_conditions); 00061 00062 /// Convenience method for detaching multiple conditions, 00063 /// for example when shutting down. 00064 ReturnCode_t detach_conditions(const ConditionSeq& conditions); 00065 00066 static WaitSet_ptr _duplicate(WaitSet_ptr obj); 00067 00068 typedef OPENDDS_SET_CMP(Condition_var, 00069 OpenDDS::DCPS::VarLess<Condition> ) ConditionSet; 00070 00071 private: 00072 ReturnCode_t detach_i(const Condition_ptr cond); 00073 void signal(Condition_ptr cond); 00074 friend class OpenDDS::DCPS::ConditionImpl; 00075 00076 ACE_Recursive_Thread_Mutex lock_; 00077 ACE_Condition_Recursive_Thread_Mutex cond_; 00078 ACE_Atomic_Op<ACE_Thread_Mutex, long> waiting_; 00079 00080 ConditionSet attached_conditions_; 00081 ConditionSet signaled_conditions_; 00082 }; 00083 00084 } // namespace DDS 00085 00086 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00087 00088 namespace TAO { 00089 00090 template<> 00091 struct OpenDDS_Dcps_Export Objref_Traits<DDS::WaitSet> { 00092 static DDS::WaitSet_ptr duplicate(DDS::WaitSet_ptr p); 00093 static void release(DDS::WaitSet_ptr p); 00094 static DDS::WaitSet_ptr nil(); 00095 static CORBA::Boolean marshal(const DDS::WaitSet_ptr p, 00096 TAO_OutputCDR & cdr); 00097 }; 00098 00099 } // namespace TAO 00100 00101 TAO_END_VERSIONED_NAMESPACE_DECL 00102 00103 #endif