OpenDDS  Snapshot(2023/04/07-19:43)
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
OpenDDS::DCPS::ReactorInterceptor Class Referenceabstract

#include <ReactorInterceptor.h>

Inheritance diagram for OpenDDS::DCPS::ReactorInterceptor:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::ReactorInterceptor:
Collaboration graph
[legend]

Classes

class  Command
 

Public Types

typedef RcHandle< CommandCommandPtr
 
- Public Types inherited from ACE_Event_Handler
typedef long Reference_Count
 

Public Member Functions

CommandPtr execute_or_enqueue (CommandPtr command)
 
virtual bool reactor_is_shut_down () const =0
 
virtual void reactor (ACE_Reactor *reactor)
 
virtual ACE_Reactorreactor () const
 
- Public Member Functions inherited from OpenDDS::DCPS::RcEventHandler
 RcEventHandler ()
 
ACE_Event_Handler::Reference_Count add_reference ()
 
ACE_Event_Handler::Reference_Count remove_reference ()
 
- Public Member Functions inherited from ACE_Event_Handler
virtual ~ACE_Event_Handler (void)
 
virtual ACE_HANDLE get_handle (void) const
 
virtual void set_handle (ACE_HANDLE)
 
virtual int priority (void) const
 
virtual void priority (int priority)
 
virtual int handle_input (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_output (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_timeout (const ACE_Time_Value &current_time, const void *act=0)
 
virtual int handle_exit (ACE_Process *)
 
virtual int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
 
virtual int handle_signal (int signum, siginfo_t *=0, ucontext_t *=0)
 
virtual int resume_handler (void)
 
virtual int handle_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual int handle_group_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual ACE_Reactor_Timer_Interfacereactor_timer_interface (void) const
 
Reference_Counting_Policyreference_counting_policy (void)
 
- Public Member Functions inherited from OpenDDS::DCPS::RcObject
virtual ~RcObject ()
 
virtual void _add_ref ()
 
virtual void _remove_ref ()
 
long ref_count () const
 
WeakObject_get_weak_object () const
 

Protected Types

enum  ReactorState { RS_NONE, RS_NOTIFIED, RS_PROCESSING }
 
- Protected Types inherited from ACE_Event_Handler
typedef ACE_Atomic_Op< ACE_SYNCH_MUTEX, Reference_CountAtomic_Reference_Count
 

Protected Member Functions

 ReactorInterceptor (ACE_Reactor *reactor, ACE_thread_t owner)
 
virtual ~ReactorInterceptor ()
 
int handle_exception (ACE_HANDLE)
 
void process_command_queue_i (ACE_Guard< ACE_Thread_Mutex > &guard)
 
typedef OPENDDS_VECTOR (CommandPtr) Queue
 
- Protected Member Functions inherited from ACE_Event_Handler
 ACE_Event_Handler (ACE_Reactor *=0, int priority=ACE_Event_Handler::LO_PRIORITY)
 
- Protected Member Functions inherited from OpenDDS::DCPS::RcObject
 RcObject ()
 

Protected Attributes

ACE_thread_t owner_
 
ACE_Thread_Mutex mutex_
 
Queue command_queue_
 
ReactorState state_
 
- Protected Attributes inherited from ACE_Event_Handler
Atomic_Reference_Count reference_count_
 

Additional Inherited Members

- Static Public Member Functions inherited from ACE_Event_Handler
static ACE_THR_FUNC_RETURN read_adapter (void *event_handler)
 
static int register_stdin_handler (ACE_Event_Handler *eh, ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr, int flags=THR_DETACHED)
 
static int remove_stdin_handler (ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr)
 
- Public Attributes inherited from ACE_Event_Handler
 LO_PRIORITY
 
 HI_PRIORITY
 
 NULL_MASK
 
 READ_MASK
 
 WRITE_MASK
 
 EXCEPT_MASK
 
 ACCEPT_MASK
 
 CONNECT_MASK
 
 TIMER_MASK
 
 QOS_MASK
 
 GROUP_QOS_MASK
 
 SIGNAL_MASK
 
 ALL_EVENTS_MASK
 
 RWE_MASK
 
 DONT_CALL
 
 ACE_EVENT_HANDLER_NOT_RESUMED
 
 ACE_REACTOR_RESUMES_HANDLER
 
 ACE_APPLICATION_RESUMES_HANDLER
 

Detailed Description

Definition at line 28 of file ReactorInterceptor.h.

Member Typedef Documentation

◆ CommandPtr

Definition at line 49 of file ReactorInterceptor.h.

Member Enumeration Documentation

◆ ReactorState

Constructor & Destructor Documentation

◆ ReactorInterceptor()

OpenDDS::DCPS::ReactorInterceptor::ReactorInterceptor ( ACE_Reactor reactor,
ACE_thread_t  owner 
)
protected

Definition at line 26 of file ReactorInterceptor.cpp.

References ACE_Event_Handler::reactor().

◆ ~ReactorInterceptor()

OpenDDS::DCPS::ReactorInterceptor::~ReactorInterceptor ( )
protectedvirtual

Definition at line 34 of file ReactorInterceptor.cpp.

35 {
36 }

Member Function Documentation

◆ execute_or_enqueue()

ReactorInterceptor::CommandPtr OpenDDS::DCPS::ReactorInterceptor::execute_or_enqueue ( CommandPtr  command)

Definition at line 38 of file ReactorInterceptor.cpp.

References command_queue_, mutex_, ACE_Reactor::notify(), OPENDDS_ASSERT, owner_, process_command_queue_i(), ACE_Event_Handler::reactor(), reactor_is_shut_down(), ACE_Guard< ACE_LOCK >::release(), RS_NONE, RS_NOTIFIED, RS_PROCESSING, ACE_Thread::self(), state_, and ACE_OS::thr_equal().

Referenced by OpenDDS::DCPS::DataLink::add_on_start_callback(), OpenDDS::DCPS::SporadicTask::cancel(), OpenDDS::DCPS::InstanceState::cancel_release(), OpenDDS::DCPS::EndHistoricSamplesMissedSweeper::cancel_timer(), OpenDDS::DCPS::PeriodicTask::disable(), OpenDDS::DCPS::MultiTask::disable(), OpenDDS::DCPS::PeriodicTask::enable(), OpenDDS::DCPS::MultiTask::enable(), OpenDDS::DCPS::RtpsUdpTransport::make_datalink(), OpenDDS::RTPS::Spdp::SpdpTransport::open(), OpenDDS::DCPS::SporadicTask::schedule(), OpenDDS::DCPS::InstanceState::schedule_release(), OpenDDS::DCPS::EndHistoricSamplesMissedSweeper::schedule_timer(), OpenDDS::DCPS::RtpsUdpReceiveStrategy::start_i(), OpenDDS::DCPS::RtpsUdpTransport::start_ice(), OpenDDS::DCPS::RtpsUdpReceiveStrategy::stop_i(), and OpenDDS::DCPS::RtpsUdpTransport::stop_ice().

39 {
40  OPENDDS_ASSERT(command);
41 
43 
44  // Only allow immediate execution if running on the reactor thread, otherwise we risk deadlock
45  // when calling into the reactor object.
46  const bool is_owner = ACE_OS::thr_equal(owner_, ACE_Thread::self());
47 
48  // If state is set to processing, the conents of command_queue_ have been swapped out
49  // so immediate execution may run jobs out of the expected order.
50  const bool is_not_processing = state_ != RS_PROCESSING;
51 
52  // If the command_queue_ is not empty, allowing execution will potentially run unexpected code
53  // which is problematic since we may be holding locks used by the unexpected code.
54  const bool is_empty = command_queue_.empty();
55 
56  // If all three of these conditions are met, it should be safe to execute
57  const bool is_safe_to_execute = is_owner && is_not_processing && is_empty;
58 
59  // Even if it's not normally safe to execute, allow immediate execution if the reactor is shut down
60  const bool immediate = is_safe_to_execute || reactor_is_shut_down();
61 
62  // Always set reactor and push to the queue
63  ACE_Reactor* local_reactor = ACE_Event_Handler::reactor();
64  command->set_reactor(local_reactor);
65  command_queue_.push_back(command);
66 
67  // But depending on whether we're running it immediately or not, we either process or notify
68  if (immediate) {
70  } else if (state_ == RS_NONE) {
72  guard.release();
73  local_reactor->notify(this);
74  }
75  return command;
76 }
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:66
void process_command_queue_i(ACE_Guard< ACE_Thread_Mutex > &guard)
int notify(ACE_Event_Handler *event_handler=0, ACE_Reactor_Mask masks=ACE_Event_Handler::EXCEPT_MASK, ACE_Time_Value *timeout=0)
static ACE_thread_t self(void)
virtual bool reactor_is_shut_down() const =0
int thr_equal(ACE_thread_t t1, ACE_thread_t t2)
virtual ACE_Reactor * reactor(void) const

◆ handle_exception()

int OpenDDS::DCPS::ReactorInterceptor::handle_exception ( ACE_HANDLE  )
protectedvirtual

Reimplemented from ACE_Event_Handler.

Definition at line 78 of file ReactorInterceptor.cpp.

References mutex_, process_command_queue_i(), and TheServiceParticipant.

79 {
80  ThreadStatusManager::Event ev(TheServiceParticipant->get_thread_status_manager());
81 
84  return 0;
85 }
void process_command_queue_i(ACE_Guard< ACE_Thread_Mutex > &guard)
#define TheServiceParticipant

◆ OPENDDS_VECTOR()

typedef OpenDDS::DCPS::ReactorInterceptor::OPENDDS_VECTOR ( CommandPtr  )
protected

◆ process_command_queue_i()

void OpenDDS::DCPS::ReactorInterceptor::process_command_queue_i ( ACE_Guard< ACE_Thread_Mutex > &  guard)
protected

Definition at line 87 of file ReactorInterceptor.cpp.

References command_queue_, mutex_, ACE_Reactor::notify(), ACE_Event_Handler::reactor(), reactor(), ACE_Guard< ACE_LOCK >::release(), RS_NONE, RS_NOTIFIED, RS_PROCESSING, and state_.

Referenced by execute_or_enqueue(), and handle_exception().

88 {
89  Queue cq;
91 
93  if (!command_queue_.empty()) {
94  cq.swap(command_queue_);
96  for (Queue::const_iterator pos = cq.begin(), limit = cq.end(); pos != limit; ++pos) {
97  (*pos)->execute();
98  }
99  }
100  if (!command_queue_.empty()) {
103  guard.release();
104  reactor->notify(this);
105  } else {
106  state_ = RS_NONE;
107  }
108 }
int release(void)
int notify(ACE_Event_Handler *event_handler=0, ACE_Reactor_Mask masks=ACE_Event_Handler::EXCEPT_MASK, ACE_Time_Value *timeout=0)
virtual ACE_Reactor * reactor() const
virtual ACE_Reactor * reactor(void) const

◆ reactor() [1/2]

void OpenDDS::DCPS::ReactorInterceptor::reactor ( ACE_Reactor reactor)
virtual

◆ reactor() [2/2]

ACE_Reactor * OpenDDS::DCPS::ReactorInterceptor::reactor ( void  ) const
virtual

◆ reactor_is_shut_down()

virtual bool OpenDDS::DCPS::ReactorInterceptor::reactor_is_shut_down ( ) const
pure virtual

Member Data Documentation

◆ command_queue_

Queue OpenDDS::DCPS::ReactorInterceptor::command_queue_
protected

Definition at line 76 of file ReactorInterceptor.h.

Referenced by execute_or_enqueue(), and process_command_queue_i().

◆ mutex_

ACE_Thread_Mutex OpenDDS::DCPS::ReactorInterceptor::mutex_
mutableprotected

◆ owner_

ACE_thread_t OpenDDS::DCPS::ReactorInterceptor::owner_
protected

Definition at line 73 of file ReactorInterceptor.h.

Referenced by execute_or_enqueue().

◆ state_

ReactorState OpenDDS::DCPS::ReactorInterceptor::state_
protected

Definition at line 77 of file ReactorInterceptor.h.

Referenced by execute_or_enqueue(), and process_command_queue_i().


The documentation for this class was generated from the following files: