DDS::WaitSet Class Reference

#include <WaitSet.h>

Inheritance diagram for DDS::WaitSet:

Inheritance graph
[legend]
Collaboration diagram for DDS::WaitSet:

Collaboration graph
[legend]
List of all members.

Public Types

typedef WaitSet_ptr _ptr_type
typedef WaitSet_var _var_type

Public Member Functions

 WaitSet ()
virtual ~WaitSet ()
ReturnCode_t wait (ConditionSeq &active_conditions, const Duration_t &timeout)
ReturnCode_t attach_condition (Condition_ptr cond)
ReturnCode_t detach_condition (Condition_ptr cond)
ReturnCode_t get_conditions (ConditionSeq &attached_conditions)
ReturnCode_t detach_conditions (const ConditionSeq &conditions)
typedef OPENDDS_SET_CMP (Condition_var, OpenDDS::DCPS::VarLess< Condition >) ConditionSet

Static Public Member Functions

static WaitSet_ptr _duplicate (WaitSet_ptr obj)

Private Member Functions

ReturnCode_t detach_i (const Condition_ptr cond)
void signal (Condition_ptr cond)

Private Attributes

ACE_Recursive_Thread_Mutex lock_
ACE_Condition_Recursive_Thread_Mutex cond_
ACE_Atomic_Op< ACE_Thread_Mutex,
long > 
waiting_
ConditionSet attached_conditions_
ConditionSet signaled_conditions_

Friends

class OpenDDS::DCPS::ConditionImpl

Detailed Description

Definition at line 40 of file WaitSet.h.


Member Typedef Documentation

typedef WaitSet_ptr DDS::WaitSet::_ptr_type

Reimplemented from OpenDDS::DCPS::LocalObject< Stub >.

Definition at line 43 of file WaitSet.h.

typedef WaitSet_var DDS::WaitSet::_var_type

Reimplemented from OpenDDS::DCPS::LocalObject< Stub >.

Definition at line 44 of file WaitSet.h.


Constructor & Destructor Documentation

DDS::WaitSet::WaitSet (  )  [inline]

Definition at line 46 of file WaitSet.h.

00047     : lock_(),
00048       cond_(lock_)
00049   {}

virtual DDS::WaitSet::~WaitSet (  )  [inline, virtual]

Definition at line 51 of file WaitSet.h.

00051 {}


Member Function Documentation

WaitSet_ptr DDS::WaitSet::_duplicate ( WaitSet_ptr  obj  )  [static]

Definition at line 169 of file WaitSet.cpp.

Referenced by OpenDDS::DCPS::ConditionImpl::attach_to_ws(), OpenDDS::DCPS::ConditionImpl::detach_from_ws(), and TAO::Objref_Traits< DDS::WaitSet >::duplicate().

00170 {
00171   if (!CORBA::is_nil(obj)) obj->_add_ref();
00172 
00173   return obj;
00174 }

ReturnCode_t DDS::WaitSet::attach_condition ( Condition_ptr  cond  ) 

Definition at line 34 of file WaitSet.cpp.

References attached_conditions_, lock_, DDS::RETCODE_BAD_PARAMETER, DDS::RETCODE_OK, DDS::RETCODE_OUT_OF_RESOURCES, DDS::RETCODE_PRECONDITION_NOT_MET, and signal().

00035 {
00036   using OpenDDS::DCPS::ConditionImpl;
00037   Condition_var condv(Condition::_duplicate(cond));
00038 
00039   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, g, lock_,
00040                    RETCODE_OUT_OF_RESOURCES);
00041   ConditionImpl* ci = dynamic_cast<ConditionImpl*>(cond);
00042 
00043   if (!ci) return RETCODE_BAD_PARAMETER;
00044 
00045   ReturnCode_t ret = ci->attach_to_ws(this);
00046 
00047   if (ret == RETCODE_OK) {
00048     attached_conditions_.insert(condv);
00049 
00050     if (condv->get_trigger_value()) signal(condv.in());
00051 
00052     return RETCODE_OK;
00053 
00054   } else if (ret == RETCODE_PRECONDITION_NOT_MET) {
00055     // RETCODE_PRECONDITION_NOT_MET means it was already in the set
00056     return RETCODE_OK;
00057   }
00058 
00059   return ret;
00060 }

ReturnCode_t DDS::WaitSet::detach_condition ( Condition_ptr  cond  ) 

Definition at line 62 of file WaitSet.cpp.

References detach_i(), lock_, and DDS::RETCODE_OUT_OF_RESOURCES.

00063 {
00064   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, g, lock_,
00065                    RETCODE_OUT_OF_RESOURCES);
00066   return detach_i(cond);
00067 }

ReturnCode_t DDS::WaitSet::detach_conditions ( const ConditionSeq conditions  ) 

Convenience method for detaching multiple conditions, for example when shutting down.

Definition at line 69 of file WaitSet.cpp.

References detach_i(), lock_, DDS::RETCODE_OK, and DDS::RETCODE_OUT_OF_RESOURCES.

00070 {
00071   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, g, lock_,
00072                    RETCODE_OUT_OF_RESOURCES);
00073 
00074   for (CORBA::ULong i = 0; i < conds.length(); ++i) {
00075     ReturnCode_t ret = detach_i(conds[ i]);
00076 
00077     if (ret != RETCODE_OK) {
00078       return ret;
00079     }
00080   }
00081 
00082   return RETCODE_OK;
00083 }

ReturnCode_t DDS::WaitSet::detach_i ( const Condition_ptr  cond  )  [private]

Definition at line 85 of file WaitSet.cpp.

References attached_conditions_, DDS::RETCODE_BAD_PARAMETER, and signaled_conditions_.

Referenced by detach_condition(), and detach_conditions().

00086 {
00087   using OpenDDS::DCPS::ConditionImpl;
00088   Condition_var condv(Condition::_duplicate(cond));
00089 
00090   ConditionImpl* ci = dynamic_cast<ConditionImpl*>(cond);
00091 
00092   if (!ci) return RETCODE_BAD_PARAMETER;
00093 
00094   ReturnCode_t ret = ci->detach_from_ws(this);
00095   attached_conditions_.erase(condv);
00096   signaled_conditions_.erase(condv);
00097   return ret;
00098 }

ReturnCode_t DDS::WaitSet::get_conditions ( ConditionSeq attached_conditions  ) 

Definition at line 100 of file WaitSet.cpp.

References attached_conditions_, copyInto(), lock_, DDS::RETCODE_OK, and DDS::RETCODE_OUT_OF_RESOURCES.

00101 {
00102   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, g, lock_,
00103                    RETCODE_OUT_OF_RESOURCES);
00104   copyInto(conds, attached_conditions_);
00105   return RETCODE_OK;
00106 }

typedef DDS::WaitSet::OPENDDS_SET_CMP ( Condition_var  ,
OpenDDS::DCPS::VarLess< Condition  
)

void DDS::WaitSet::signal ( Condition_ptr  cond  )  [private]

Definition at line 158 of file WaitSet.cpp.

References attached_conditions_, cond_, lock_, and signaled_conditions_.

Referenced by attach_condition().

00159 {
00160   Condition_var condv(Condition::_duplicate(condition));
00161   ACE_GUARD(ACE_Recursive_Thread_Mutex, g, lock_);
00162 
00163   if (attached_conditions_.find(condv) != attached_conditions_.end()) {
00164     signaled_conditions_.insert(condv);
00165     cond_.signal();
00166   }
00167 }

ReturnCode_t DDS::WaitSet::wait ( ConditionSeq active_conditions,
const Duration_t timeout 
)

Definition at line 108 of file WaitSet.cpp.

References attached_conditions_, cond_, copyInto(), DDS::DURATION_INFINITE_NSEC, DDS::DURATION_INFINITE_SEC, OpenDDS::DCPS::duration_to_absolute_time_value(), lock_, OpenDDS::DCPS::non_negative_duration(), DDS::RETCODE_BAD_PARAMETER, DDS::RETCODE_ERROR, DDS::RETCODE_OK, DDS::RETCODE_OUT_OF_RESOURCES, DDS::RETCODE_PRECONDITION_NOT_MET, DDS::RETCODE_TIMEOUT, signaled_conditions_, and waiting_.

00110 {
00111   if (waiting_.value()) return RETCODE_PRECONDITION_NOT_MET;
00112 
00113   if (!OpenDDS::DCPS::non_negative_duration(timeout))
00114     return DDS::RETCODE_BAD_PARAMETER;
00115 
00116   ACE_Time_Value deadline;
00117   ACE_Time_Value* p_deadline = 0;
00118 
00119   if (timeout.sec != DURATION_INFINITE_SEC ||
00120       timeout.nanosec != DURATION_INFINITE_NSEC) {
00121     deadline = OpenDDS::DCPS::duration_to_absolute_time_value(timeout);
00122     p_deadline = &deadline;
00123   }
00124 
00125   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, g, lock_,
00126                    RETCODE_OUT_OF_RESOURCES);
00127   waiting_ = 1;
00128   signaled_conditions_.clear();
00129 
00130   for (ConditionSet::const_iterator iter = attached_conditions_.begin(),
00131        end = attached_conditions_.end(); iter != end; ++iter) {
00132     if ((*iter)->get_trigger_value()) {
00133       signaled_conditions_.insert(*iter);
00134     }
00135   }
00136 
00137   int error = 0;
00138 
00139   while ((attached_conditions_.empty() || signaled_conditions_.empty())
00140          && !error) {
00141     if (cond_.wait(p_deadline) == -1) error = errno;
00142   }
00143 
00144   copyInto(active_conditions, signaled_conditions_);
00145   signaled_conditions_.clear();
00146   waiting_ = 0;
00147 
00148   switch (error) {
00149   case 0:
00150     return RETCODE_OK;
00151   case ETIME:
00152     return RETCODE_TIMEOUT;
00153   default:
00154     return RETCODE_ERROR;
00155   }
00156 }


Friends And Related Function Documentation

friend class OpenDDS::DCPS::ConditionImpl [friend]

Definition at line 74 of file WaitSet.h.


Member Data Documentation

ConditionSet DDS::WaitSet::attached_conditions_ [private]

Definition at line 80 of file WaitSet.h.

Referenced by attach_condition(), detach_i(), get_conditions(), signal(), and wait().

ACE_Condition_Recursive_Thread_Mutex DDS::WaitSet::cond_ [private]

Definition at line 77 of file WaitSet.h.

Referenced by signal(), and wait().

ACE_Recursive_Thread_Mutex DDS::WaitSet::lock_ [private]

Definition at line 76 of file WaitSet.h.

Referenced by attach_condition(), detach_condition(), detach_conditions(), get_conditions(), signal(), and wait().

ConditionSet DDS::WaitSet::signaled_conditions_ [private]

Definition at line 81 of file WaitSet.h.

Referenced by detach_i(), signal(), and wait().

ACE_Atomic_Op<ACE_Thread_Mutex, long> DDS::WaitSet::waiting_ [private]

Definition at line 78 of file WaitSet.h.

Referenced by wait().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:06 2016 for OpenDDS by  doxygen 1.4.7