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 46 of file WaitSet.h.


Member Typedef Documentation

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

Definition at line 49 of file WaitSet.h.

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

Definition at line 50 of file WaitSet.h.


Constructor & Destructor Documentation

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

Definition at line 52 of file WaitSet.h.

00053     : lock_(),
00054       cond_(lock_)
00055   {}

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

Definition at line 57 of file WaitSet.h.

00057 {}


Member Function Documentation

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

Reimplemented from CORBA::LocalObject.

Definition at line 171 of file WaitSet.cpp.

References OpenDDS::DCPS::LocalObjectBase::_add_ref(), and CORBA::is_nil().

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

Here is the call graph for this function:

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

Definition at line 36 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().

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

Here is the call graph for this function:

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

Definition at line 64 of file WaitSet.cpp.

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

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

Here is the call graph for this function:

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

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

Definition at line 71 of file WaitSet.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 87 of file WaitSet.cpp.

References attached_conditions_, DDS::RETCODE_BAD_PARAMETER, and signaled_conditions_.

Referenced by detach_condition(), and detach_conditions().

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

Here is the caller graph for this function:

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

Definition at line 102 of file WaitSet.cpp.

References attached_conditions_, lock_, DDS::RETCODE_OK, and DDS::RETCODE_OUT_OF_RESOURCES.

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

typedef DDS::WaitSet::OPENDDS_SET_CMP ( Condition_var  ,
OpenDDS::DCPS::VarLess< Condition  
)
void DDS::WaitSet::signal ( Condition_ptr  cond  )  [private]

Definition at line 160 of file WaitSet.cpp.

References attached_conditions_, cond_, lock_, ACE_Condition< ACE_Recursive_Thread_Mutex >::signal(), and signaled_conditions_.

Referenced by attach_condition().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 110 of file WaitSet.cpp.

References attached_conditions_, cond_, DDS::DURATION_INFINITE_NSEC, DDS::DURATION_INFINITE_SEC, OpenDDS::DCPS::duration_to_absolute_time_value(), lock_, DDS::Duration_t::nanosec, 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, DDS::Duration_t::sec, signaled_conditions_, ACE_Atomic_Op< ACE_Thread_Mutex, long >::value(), ACE_Condition< ACE_Recursive_Thread_Mutex >::wait(), and waiting_.

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

Here is the call graph for this function:


Friends And Related Function Documentation

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

Definition at line 80 of file WaitSet.h.


Member Data Documentation

ConditionSet DDS::WaitSet::attached_conditions_ [private]

Definition at line 86 of file WaitSet.h.

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

Definition at line 83 of file WaitSet.h.

Referenced by signal(), and wait().

ConditionSet DDS::WaitSet::signaled_conditions_ [private]

Definition at line 87 of file WaitSet.h.

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

Definition at line 84 of file WaitSet.h.

Referenced by wait().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1