diff options
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Reactor.cpp | 159 | ||||
-rw-r--r-- | ace/Reactor.h | 48 | ||||
-rw-r--r-- | ace/Reactor.i | 290 | ||||
-rw-r--r-- | ace/Reactor_Impl.h | 12 | ||||
-rw-r--r-- | ace/Select_Reactor_T.cpp | 6 | ||||
-rw-r--r-- | ace/Select_Reactor_T.h | 15 | ||||
-rw-r--r-- | ace/Select_Reactor_T.i | 13 | ||||
-rw-r--r-- | ace/TP_Reactor.cpp | 7 | ||||
-rw-r--r-- | ace/WFMO_Reactor.cpp | 5 | ||||
-rw-r--r-- | ace/WFMO_Reactor.h | 16 | ||||
-rw-r--r-- | ace/WFMO_Reactor.i | 13 |
11 files changed, 388 insertions, 196 deletions
diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp index ebf860d9786..532c15b04f0 100644 --- a/ace/Reactor.cpp +++ b/ace/Reactor.cpp @@ -37,7 +37,7 @@ ACE_Reactor::ACE_Reactor (ACE_Reactor_Impl *impl, #if defined (ACE_USE_TP_REACTOR_FOR_REACTOR_IMPL) ACE_NEW (impl, ACE_TP_Reactor); - #else + #else ACE_NEW (impl, ACE_Select_Reactor); #endif /* ACE_USE_TP_REACTOR_FOR_REACTOR_IMPL */ @@ -68,9 +68,6 @@ ACE_Reactor *ACE_Reactor::reactor_ = 0; // only delete it safely if we created it!) int ACE_Reactor::delete_reactor_ = 0; -// Terminate the eventloop. -sig_atomic_t ACE_Reactor::end_event_loop_ = 0; - ACE_Reactor * ACE_Reactor::instance (void) { @@ -128,134 +125,130 @@ ACE_Reactor::close_singleton (void) } } -// Run the event loop until the <ACE_Reactor::handle_events> method -// returns -1 or the <end_event_loop> method is invoked. - int -ACE_Reactor::run_event_loop (void) +ACE_Reactor::check_reconfiguration (void *) { - ACE_TRACE ("ACE_Reactor::run_event_loop"); - - while (ACE_Reactor::end_event_loop_ == 0) - { - int result = ACE_Reactor::instance ()->handle_events (); - #if !defined (ACE_HAS_WINCE) - if (ACE_Service_Config::reconfig_occurred ()) - ACE_Service_Config::reconfigure (); - else -#endif /* !ACE_HAS_WINCE */ - if (result == -1) - return -1; + if (ACE_Service_Config::reconfig_occurred ()) + { + ACE_Service_Config::reconfigure (); + return 1; } - /* NOTREACHED */ +#endif /* ACE_HAS_WINCE */ return 0; } -// Run the event loop until the <ACE_Reactor::handle_events> -// method returns -1, the <end_event_loop> method -// is invoked, or the <ACE_Time_Value> expires. - int -ACE_Reactor::run_event_loop (ACE_Time_Value &tv) +ACE_Reactor::run_reactor_event_loop (REACTOR_EVENT_HOOK eh) { - ACE_TRACE ("ACE_Reactor::run_event_loop"); + ACE_TRACE ("ACE_Reactor::run_reactor_event_loop"); - while (ACE_Reactor::end_event_loop_ == 0) + while (1) { - int result = ACE_Reactor::instance ()->handle_events (tv); - -#if !defined (ACE_HAS_WINCE) - if (ACE_Service_Config::reconfig_occurred ()) - ACE_Service_Config::reconfigure (); - else -#endif /* !ACE_HAS_WINCE */ - if (result <= 0) - return result; + int result = this->implementation_->handle_events (); + + if (eh != 0 && (*eh)(0)) + continue; + else if (result == -1 && this->implementation_->deactivated ()) + return 0; + else if (result == -1) + return -1; } - /* NOTREACHED */ return 0; } -// Run the event loop until the <ACE_Reactor::alertable_handle_events> method -// returns -1 or the <end_event_loop> method is invoked. - int -ACE_Reactor::run_alertable_event_loop (void) +ACE_Reactor::run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK eh) { - ACE_TRACE ("ACE_Reactor::run_event_loop"); + ACE_TRACE ("ACE_Reactor::run_alertable_reactor_event_loop"); - while (ACE_Reactor::end_event_loop_ == 0) + while (1) { - int result = ACE_Reactor::instance ()->alertable_handle_events (); - -#if !defined (ACE_HAS_WINCE) - if (ACE_Service_Config::reconfig_occurred ()) - ACE_Service_Config::reconfigure (); - else -#endif /* !ACE_HAS_WINCE */ - - if (result == -1) - return -1; + int result = this->implementation_->alertable_handle_events (); + + if (eh != 0 && (*eh)(0)) + continue; + else if (result == -1 && this->implementation_->deactivated ()) + return 0; + else if (result == -1) + return -1; } /* NOTREACHED */ return 0; } -// Run the event loop until the <ACE_Reactor::alertable_handle_events> -// method returns -1, the <end_event_loop> method -// is invoked, or the <ACE_Time_Value> expires. - int -ACE_Reactor::run_alertable_event_loop (ACE_Time_Value &tv) +ACE_Reactor::run_reactor_event_loop (ACE_Time_Value &tv, + REACTOR_EVENT_HOOK eh) { - ACE_TRACE ("ACE_Reactor::run_event_loop"); + ACE_TRACE ("ACE_Reactor::run_reactor_event_loop"); - while (ACE_Reactor::end_event_loop_ == 0) + while (1) { - int result = ACE_Reactor::instance ()->alertable_handle_events (tv); - -#if !defined (ACE_HAS_WINCE) - if (ACE_Service_Config::reconfig_occurred ()) - ACE_Service_Config::reconfigure (); - else -#endif /* !ACE_HAS_WINCE */ - if (result <= 0) - return result; + int result = this->implementation_->handle_events (tv); + + if (eh != 0 && (*eh)(0)) + continue; + else if (result == -1 && this->implementation_->deactivated ()) + return 0; + else if (result <= 0) + return result; } /* NOTREACHED */ return 0; } -void -ACE_Reactor::reset_event_loop (void) +int +ACE_Reactor::run_alertable_reactor_event_loop (ACE_Time_Value &tv, + REACTOR_EVENT_HOOK eh) { - ACE_TRACE ("ACE_Reactor::reset_event_loop"); + ACE_TRACE ("ACE_Reactor::run_alertable_reactor_event_loop"); + + while (1) + { + int result = this->implementation_->alertable_handle_events (tv); + + if (eh != 0 && (*eh)(0)) + continue; + else if (result == -1 && this->implementation_->deactivated ()) + return 0; + else if (result <= 0) + return result; + } - ACE_Reactor::end_event_loop_ = 0; + /* NOTREACHED */ + return 0; } int -ACE_Reactor::end_event_loop (void) +ACE_Reactor::end_reactor_event_loop (void) { - ACE_TRACE ("ACE_Reactor::end_event_loop"); - - ACE_Reactor::end_event_loop_ = 1; + ACE_TRACE ("ACE_Reactor::end_reactor_event_loop"); - // Wakeup all threads waiting in the Reactor. - ACE_Reactor::instance ()->wakeup_all_threads (); + this->implementation_->deactivate (1); return 0; } int -ACE_Reactor::event_loop_done (void) +ACE_Reactor::reactor_event_loop_done (void) { - ACE_TRACE ("ACE_Reactor::event_loop_done"); - return ACE_Reactor::end_event_loop_ != 0; + ACE_TRACE ("ACE_Reactor::reactor_event_loop_done"); + return this->implementation_->deactivated (); +} + // Report if the <ACE_Reactor::instance>'s event loop is finished. + +void +ACE_Reactor::reset_reactor_event_loop (void) +{ + ACE_TRACE ("ACE_Reactor::reset_event_loop"); + + this->implementation_->deactivate (0); } + // Resets the <ACE_Reactor::end_event_loop_> static so that the + // <run_event_loop> method can be restarted. void ACE_Reactor::dump (void) const diff --git a/ace/Reactor.h b/ace/Reactor.h index e5acd926d5f..bbb2fa635f4 100644 --- a/ace/Reactor.h +++ b/ace/Reactor.h @@ -62,6 +62,13 @@ public: // changes enabled bits). }; + typedef int (*REACTOR_EVENT_HOOK)(void*); + // You can add a hook to various run_event methods and the hook will + // be called after handling every reactor event. If this function + // returns 0, run_reactor_event_loop will check for the return value of + // handle_event. If it is -1, the the run_reactor_event_loop will return + // (pre-maturely.) + static ACE_Reactor *instance (void); // Get pointer to a process-wide <ACE_Reactor>. @@ -74,7 +81,7 @@ public: static void close_singleton (void); // Delete the dynamically allocated Singleton - // = Reactor event loop management methods. + // = Singleton reactor event loop management methods. // Note that these method ONLY work on the "Singleton Reactor," // i.e., the one returned from <ACE_Reactor::instance>. @@ -103,6 +110,42 @@ public: // Resets the <ACE_Reactor::end_event_loop_> static so that the // <run_event_loop> method can be restarted. + static int check_reconfiguration (void *); + // The singleton reactor is used by the service_configurator. + // Therefore, we must check for the reconfiguration request and + // handle it after handling an event. + + + // = Reactor event loop management methods. + + // These methods work with an instance of a reactor. + virtual int run_reactor_event_loop (REACTOR_EVENT_HOOK = 0); + virtual int run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK = 0); + // Run the event loop until the + // <ACE_Reactor::handle_events/ACE_Reactor::alertable_handle_events> + // method returns -1 or the <end_event_loop> method is invoked. + + virtual int run_reactor_event_loop (ACE_Time_Value &tv, + REACTOR_EVENT_HOOK = 0); + virtual int run_alertable_reactor_event_loop (ACE_Time_Value &tv, + REACTOR_EVENT_HOOK = 0); + // Run the event loop until the <ACE_Reactor::handle_events> or + // <ACE_Reactor::alertable_handle_events> methods returns -1, the + // <end_event_loop> method is invoked, or the <ACE_Time_Value> + // expires. + + virtual int end_reactor_event_loop (void); + // Instruct the <ACE_Reactor::instance> to terminate its event loop + // and notifies the <ACE_Reactor::instance> so that it can wake up + // and close down gracefully. + + virtual int reactor_event_loop_done (void); + // Report if the <ACE_Reactor::instance>'s event loop is finished. + + virtual void reset_reactor_event_loop (void); + // Resets the <ACE_Reactor::end_event_loop_> static so that the + // <run_event_loop> method can be restarted. + ACE_Reactor (ACE_Reactor_Impl *implementation = 0, int delete_implementation = 0); // Create the Reactor using <implementation>. The flag @@ -476,9 +519,6 @@ protected: static int delete_reactor_; // Must delete the <reactor_> singleton if non-0. - static sig_atomic_t end_event_loop_; - // Terminate the event loop of the singleton Reactor. - ACE_Reactor (const ACE_Reactor &); ACE_Reactor &operator = (const ACE_Reactor &); // Deny access since member-wise won't work... diff --git a/ace/Reactor.i b/ace/Reactor.i index ba4c8dd01e9..c197c7f325a 100644 --- a/ace/Reactor.i +++ b/ace/Reactor.i @@ -23,11 +23,91 @@ ACE_Reactor::current_info (ACE_HANDLE handle, return this->implementation ()->current_info (handle, size); } -ACE_INLINE int +// Run the event loop until the <ACE_Reactor::handle_events> method +// returns -1 or the <end_event_loop> method is invoked. + +ACE_INLINE int +ACE_Reactor::run_event_loop (void) +{ + ACE_TRACE ("ACE_Reactor::run_event_loop"); + + return + ACE_Reactor::instance () + ->run_reactor_event_loop (ACE_Reactor::check_reconfiguration); +} + +// Run the event loop until the <ACE_Reactor::handle_events> +// method returns -1, the <end_event_loop> method +// is invoked, or the <ACE_Time_Value> expires. + +ACE_INLINE int +ACE_Reactor::run_event_loop (ACE_Time_Value &tv) +{ + ACE_TRACE ("ACE_Reactor::run_event_loop"); + + return + ACE_Reactor::instance () + ->run_reactor_event_loop (tv, + ACE_Reactor::check_reconfiguration); +} + +// Run the event loop until the <ACE_Reactor::alertable_handle_events> method +// returns -1 or the <end_event_loop> method is invoked. + +ACE_INLINE int +ACE_Reactor::run_alertable_event_loop (void) +{ + ACE_TRACE ("ACE_Reactor::run_alertable_event_loop"); + + return + ACE_Reactor::instance () + ->run_alertable_reactor_event_loop (ACE_Reactor::check_reconfiguration); +} + +// Run the event loop until the <ACE_Reactor::alertable_handle_events> +// method returns -1, the <end_event_loop> method +// is invoked, or the <ACE_Time_Value> expires. + +ACE_INLINE int +ACE_Reactor::run_alertable_event_loop (ACE_Time_Value &tv) +{ + ACE_TRACE ("ACE_Reactor::run_alertable_event_loop"); + + return + ACE_Reactor::instance () + ->run_alertable_reactor_event_loop (tv, + ACE_Reactor::check_reconfiguration); +} + +ACE_INLINE void +ACE_Reactor::reset_event_loop (void) +{ + ACE_TRACE ("ACE_Reactor::reset_event_loop"); + + ACE_Reactor::instance ()->reset_reactor_event_loop (); +} + +ACE_INLINE int +ACE_Reactor::end_event_loop (void) +{ + ACE_TRACE ("ACE_Reactor::end_event_loop"); + ACE_Reactor::instance ()->end_reactor_event_loop (); + + return 0; +} + +ACE_INLINE int +ACE_Reactor::event_loop_done (void) +{ + ACE_TRACE ("ACE_Reactor::event_loop_done"); + return ACE_Reactor::instance ()->reactor_event_loop_done (); +} + +ACE_INLINE int ACE_Reactor::open (size_t size, - int restart, - ACE_Sig_Handler *signal_handler, - ACE_Timer_Queue *timer_queue) + int restart, + ACE_Sig_Handler *signal_handler, + ACE_Timer_Queue *timer_queue) { return this->implementation ()->open (size, restart, @@ -46,46 +126,46 @@ ACE_Reactor::set_timer_queue (ACE_Timer_Queue *timer_queue) return this->implementation ()->set_timer_queue (timer_queue); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::close (void) { return this->implementation ()->close (); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::work_pending (const ACE_Time_Value &max_wait_time) { return this->implementation ()->work_pending (max_wait_time); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::handle_events (ACE_Time_Value *max_wait_time) { return this->implementation ()->handle_events (max_wait_time); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::alertable_handle_events (ACE_Time_Value *max_wait_time) { return this->implementation ()->alertable_handle_events (max_wait_time); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::handle_events (ACE_Time_Value &max_wait_time) { return this->implementation ()->handle_events (max_wait_time); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::alertable_handle_events (ACE_Time_Value &max_wait_time) { return this->implementation ()->alertable_handle_events (max_wait_time); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask) + ACE_Reactor_Mask mask) { int result = this->implementation ()->register_handler (event_handler, mask); @@ -96,10 +176,10 @@ ACE_Reactor::register_handler (ACE_Event_Handler *event_handler, return result; } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (ACE_HANDLE io_handle, - ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask) + ACE_Event_Handler *event_handler, + ACE_Reactor_Mask mask) { int result = this->implementation ()->register_handler (io_handle, event_handler, @@ -110,12 +190,12 @@ ACE_Reactor::register_handler (ACE_HANDLE io_handle, return result; } - + #if defined (ACE_WIN32) -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (ACE_Event_Handler *event_handler, - ACE_HANDLE event_handle) + ACE_HANDLE event_handle) { int result = this->implementation ()->register_handler (event_handler, event_handle); @@ -125,14 +205,14 @@ ACE_Reactor::register_handler (ACE_Event_Handler *event_handler, return result; } - + #endif /* ACE_WIN32 */ -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (ACE_HANDLE event_handle, - ACE_HANDLE io_handle, - ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask) + ACE_HANDLE io_handle, + ACE_Event_Handler *event_handler, + ACE_Reactor_Mask mask) { int result = this->implementation ()->register_handler (event_handle, io_handle, @@ -144,11 +224,11 @@ ACE_Reactor::register_handler (ACE_HANDLE event_handle, return result; } - -ACE_INLINE int + +ACE_INLINE int ACE_Reactor::register_handler (const ACE_Handle_Set &handles, - ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask) + ACE_Event_Handler *event_handler, + ACE_Reactor_Mask mask) { int result = this->implementation ()->register_handler (handles, event_handler, @@ -156,16 +236,16 @@ ACE_Reactor::register_handler (const ACE_Handle_Set &handles, if (result != -1) // Assign *this* <Reactor> to the <Event_Handler>. event_handler->reactor (this); - + return result; } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (int signum, - ACE_Event_Handler *new_sh, - ACE_Sig_Action *new_disp, - ACE_Event_Handler **old_sh, - ACE_Sig_Action *old_disp) + ACE_Event_Handler *new_sh, + ACE_Sig_Action *new_disp, + ACE_Event_Handler **old_sh, + ACE_Sig_Action *old_disp) { return this->implementation ()->register_handler (signum, new_sh, @@ -174,45 +254,45 @@ ACE_Reactor::register_handler (int signum, old_disp); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::register_handler (const ACE_Sig_Set &sigset, - ACE_Event_Handler *new_sh, - ACE_Sig_Action *new_disp) + ACE_Event_Handler *new_sh, + ACE_Sig_Action *new_disp) { return this->implementation ()->register_handler (sigset, new_sh, new_disp); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::remove_handler (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask) + ACE_Reactor_Mask mask) { return this->implementation ()->remove_handler (event_handler, mask); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::remove_handler (ACE_HANDLE handle, - ACE_Reactor_Mask mask) + ACE_Reactor_Mask mask) { return this->implementation ()->remove_handler (handle, mask); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::remove_handler (const ACE_Handle_Set &handle_set, - ACE_Reactor_Mask mask) + ACE_Reactor_Mask mask) { return this->implementation ()->remove_handler (handle_set, mask); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::remove_handler (int signum, - ACE_Sig_Action *new_disp, - ACE_Sig_Action *old_disp, - int sigkey) + ACE_Sig_Action *new_disp, + ACE_Sig_Action *old_disp, + int sigkey) { return this->implementation ()->remove_handler (signum, new_disp, @@ -220,67 +300,67 @@ ACE_Reactor::remove_handler (int signum, sigkey); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::remove_handler (const ACE_Sig_Set &sigset) { return this->implementation ()->remove_handler (sigset); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::suspend_handler (ACE_Event_Handler *event_handler) { return this->implementation ()->suspend_handler (event_handler); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::suspend_handler (ACE_HANDLE handle) { return this->implementation ()->suspend_handler (handle); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::suspend_handler (const ACE_Handle_Set &handles) { return this->implementation ()->suspend_handler (handles); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::suspend_handlers (void) { return this->implementation ()->suspend_handlers (); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::resume_handler (ACE_Event_Handler *event_handler) { return this->implementation ()->resume_handler (event_handler); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::resume_handler (ACE_HANDLE handle) { return this->implementation ()->resume_handler (handle); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::resume_handler (const ACE_Handle_Set &handles) { return this->implementation ()->resume_handler (handles); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::resume_handlers (void) { return this->implementation ()->resume_handlers (); } -ACE_INLINE long +ACE_INLINE long ACE_Reactor::schedule_timer (ACE_Event_Handler *event_handler, - const void *arg, - const ACE_Time_Value &delta, - const ACE_Time_Value &interval) + const void *arg, + const ACE_Time_Value &delta, + const ACE_Time_Value &interval) { int result = this->implementation ()->schedule_timer (event_handler, arg, @@ -293,28 +373,28 @@ ACE_Reactor::schedule_timer (ACE_Event_Handler *event_handler, return result; } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::cancel_timer (ACE_Event_Handler *event_handler, - int dont_call_handle_close) + int dont_call_handle_close) { return this->implementation ()->cancel_timer (event_handler, dont_call_handle_close); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::cancel_timer (long timer_id, - const void **arg, - int dont_call_handle_close) + const void **arg, + int dont_call_handle_close) { return this->implementation ()->cancel_timer (timer_id, arg, dont_call_handle_close); } - -ACE_INLINE int + +ACE_INLINE int ACE_Reactor::schedule_wakeup (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask masks_to_be_added) + ACE_Reactor_Mask masks_to_be_added) { int result = this->implementation ()->schedule_wakeup (event_handler, masks_to_be_added); @@ -324,73 +404,73 @@ ACE_Reactor::schedule_wakeup (ACE_Event_Handler *event_handler, return result; } - -ACE_INLINE int + +ACE_INLINE int ACE_Reactor::schedule_wakeup (ACE_HANDLE handle, - ACE_Reactor_Mask masks_to_be_added) + ACE_Reactor_Mask masks_to_be_added) { return implementation ()->schedule_wakeup (handle, masks_to_be_added); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::cancel_wakeup (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask masks_to_be_cleared) + ACE_Reactor_Mask masks_to_be_cleared) { return this->implementation ()->cancel_wakeup (event_handler, masks_to_be_cleared); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::cancel_wakeup (ACE_HANDLE handle, - ACE_Reactor_Mask masks_to_be_cleared) + ACE_Reactor_Mask masks_to_be_cleared) { return this->implementation ()->cancel_wakeup (handle, masks_to_be_cleared); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::notify (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask, - ACE_Time_Value *tv) + ACE_Reactor_Mask mask, + ACE_Time_Value *tv) { return this->implementation ()->notify (event_handler, mask, tv); } -ACE_INLINE void +ACE_INLINE void ACE_Reactor::max_notify_iterations (int iterations) { this->implementation ()->max_notify_iterations (iterations); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::max_notify_iterations (void) { return this->implementation ()->max_notify_iterations (); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::handler (ACE_HANDLE handle, - ACE_Reactor_Mask mask, - ACE_Event_Handler **event_handler) + ACE_Reactor_Mask mask, + ACE_Event_Handler **event_handler) { return this->implementation ()->handler (handle, mask, event_handler); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::handler (int signum, - ACE_Event_Handler **event_handler) + ACE_Event_Handler **event_handler) { return this->implementation ()->handler (signum, event_handler); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::initialized (void) { return this->implementation ()->initialized (); @@ -402,73 +482,73 @@ ACE_Reactor::lock (void) return this->implementation ()->lock (); } -ACE_INLINE void +ACE_INLINE void ACE_Reactor::wakeup_all_threads (void) { this->implementation ()->wakeup_all_threads (); } -ACE_INLINE int -ACE_Reactor::owner (ACE_thread_t new_owner, - ACE_thread_t *old_owner) +ACE_INLINE int +ACE_Reactor::owner (ACE_thread_t new_owner, + ACE_thread_t *old_owner) { - return this->implementation ()->owner (new_owner, + return this->implementation ()->owner (new_owner, old_owner); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::owner (ACE_thread_t *owner) { return this->implementation ()->owner (owner); } -ACE_INLINE void +ACE_INLINE void ACE_Reactor::requeue_position (int position) { this->implementation ()->requeue_position (position); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::requeue_position (void) { return this->implementation ()->requeue_position (); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::mask_ops (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask, - int ops) + ACE_Reactor_Mask mask, + int ops) { return this->implementation ()->mask_ops (event_handler, mask, ops); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::mask_ops (ACE_HANDLE handle, - ACE_Reactor_Mask mask, - int ops) + ACE_Reactor_Mask mask, + int ops) { return this->implementation ()->mask_ops (handle, mask, ops); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::ready_ops (ACE_Event_Handler *event_handler, - ACE_Reactor_Mask mask, - int ops) + ACE_Reactor_Mask mask, + int ops) { return this->implementation ()->ready_ops (event_handler, mask, ops); } -ACE_INLINE int +ACE_INLINE int ACE_Reactor::ready_ops (ACE_HANDLE handle, - ACE_Reactor_Mask mask, - int ops) + ACE_Reactor_Mask mask, + int ops) { return this->implementation ()->ready_ops (handle, mask, diff --git a/ace/Reactor_Impl.h b/ace/Reactor_Impl.h index 85c3033534c..7eb92659812 100644 --- a/ace/Reactor_Impl.h +++ b/ace/Reactor_Impl.h @@ -155,6 +155,18 @@ public: // return when the system queues an I/O completion routine or an // Asynchronous Procedure Call. + // = Event handling control. + + virtual int deactivated (void) = 0; + // Return the status of Reactor. If this function returns 0, the reactor is + // actively handling events. If it returns non-zero, <handling_events> and + // <handle_alertable_events> return -1 immediately. + + virtual void deactivate (int do_stop) = 0; + // Control whether the Reactor will handle any more incoming events or not. + // If <do_stop> == 1, the Reactor will be disabled. By default, a reactor + // is in active state and can be deactivated/reactived as wish. + // = Register and remove Handlers. virtual int register_handler (ACE_Event_Handler *event_handler, diff --git a/ace/Select_Reactor_T.cpp b/ace/Select_Reactor_T.cpp index 83f9d3d29eb..ab1b8f654ac 100644 --- a/ace/Select_Reactor_T.cpp +++ b/ace/Select_Reactor_T.cpp @@ -476,7 +476,9 @@ ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::ACE_Select_Reactor_T int disable_notify_pipe, ACE_Reactor_Notify *notify) : token_ (*this), - lock_adapter_ (token_) + lock_adapter_ (token_), + deactivated_ (0) + { ACE_TRACE ("ACE_Select_Reactor_T::ACE_Select_Reactor_T"); @@ -1166,7 +1168,7 @@ ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::handle_events ACE_GUARD_RETURN (ACE_SELECT_REACTOR_TOKEN, ace_mon, this->token_, -1); if (ACE_OS::thr_equal (ACE_Thread::self (), - this->owner_) == 0) + this->owner_) == 0 || this->deactivated_) return -1; // Update the countdown to reflect time waiting for the mutex. diff --git a/ace/Select_Reactor_T.h b/ace/Select_Reactor_T.h index 6c6a41e71e5..e4ee05b97ea 100644 --- a/ace/Select_Reactor_T.h +++ b/ace/Select_Reactor_T.h @@ -193,6 +193,18 @@ public: // Current <alertable_handle_events> is identical to // <handle_events>. + // = Event handling control. + + virtual int deactivated (void); + // Return the status of Reactor. If this function returns 0, the reactor is + // actively handling events. If it returns non-zero, <handling_events> and + // <handle_alertable_events> return -1 immediately. + + virtual void deactivate (int do_stop); + // Control whether the Reactor will handle any more incoming events or not. + // If <do_stop> == 1, the Reactor will be disabled. By default, a reactor + // is in active state and can be deactivated/reactived as wish. + // = Register and remove <ACE_Event_Handler>s. virtual int register_handler (ACE_Event_Handler *eh, ACE_Reactor_Mask mask); @@ -600,6 +612,9 @@ protected: int handle_events_i (ACE_Time_Value *max_wait_time = 0); // Stops the VC++ compiler from bitching about exceptions and destructors + sig_atomic_t deactivated_; + // This flag is used to keep track of whether we are actively handling + // events or not. private: ACE_UNIMPLEMENTED_FUNC (ACE_Select_Reactor_T (const ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN> &)) diff --git a/ace/Select_Reactor_T.i b/ace/Select_Reactor_T.i index f394c01053b..9c447a5d50b 100644 --- a/ace/Select_Reactor_T.i +++ b/ace/Select_Reactor_T.i @@ -219,6 +219,19 @@ ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::alertable_handle_events (ACE_Tim return this->handle_events (max_wait_time); } +template <class ACE_SELECT_REACTOR_TOKEN> /* ACE_INLINE */ int +ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::deactivated (void) +{ + return this->deactivated_; +} + +template <class ACE_SELECT_REACTOR_TOKEN> /* ACE_INLINE */ void +ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::deactivate (int do_stop) +{ + this->deactivated_ = do_stop; + this->wakeup_all_threads (); +} + template <class ACE_SELECT_REACTOR_TOKEN> /* ACE_INLINE */ size_t ACE_Select_Reactor_T<ACE_SELECT_REACTOR_TOKEN>::size (void) { diff --git a/ace/TP_Reactor.cpp b/ace/TP_Reactor.cpp index f50449e9b98..897f09a27ab 100644 --- a/ace/TP_Reactor.cpp +++ b/ace/TP_Reactor.cpp @@ -130,6 +130,13 @@ ACE_TP_Reactor::handle_events (ACE_Time_Value *max_wait_time) return -1; } + // After acquiring the lock, check if we have been deactivated. + if (this->deactivated_) + { + ACE_MT (this->token_.release ()); + return -1; + } + // We got the lock, lets handle some events. Note: this method will // *not* dispatch any handlers. It will dispatch timeouts and // signals. diff --git a/ace/WFMO_Reactor.cpp b/ace/WFMO_Reactor.cpp index aa213e26d27..c41cf1ffa91 100644 --- a/ace/WFMO_Reactor.cpp +++ b/ace/WFMO_Reactor.cpp @@ -979,7 +979,8 @@ ACE_WFMO_Reactor::ACE_WFMO_Reactor (ACE_Sig_Handler *sh, active_threads_ (0), owner_ (ACE_Thread::self ()), change_state_thread_ (0), - open_for_business_ (0) + open_for_business_ (0), + deactivated_ (0) { if (this->open (ACE_WFMO_Reactor::DEFAULT_SIZE, 0, sh, tq) == -1) ACE_ERROR ((LM_ERROR, ASYS_TEXT ("%p\n"), ASYS_TEXT ("WFMO_Reactor"))); @@ -1399,7 +1400,7 @@ ACE_WFMO_Reactor::event_handling (ACE_Time_Value *max_wait_time, ACE_TRACE ("ACE_WFMO_Reactor::event_handling"); // Make sure we are not closed - if (!this->open_for_business_) + if (!this->open_for_business_ || this->deactivated_) return -1; // Stash the current time -- the destructor of this object will diff --git a/ace/WFMO_Reactor.h b/ace/WFMO_Reactor.h index 8b046c9730d..a9863b094d4 100644 --- a/ace/WFMO_Reactor.h +++ b/ace/WFMO_Reactor.h @@ -609,6 +609,18 @@ public: // <WaitForMultipleObjects> for the <bAlertable> option. + // = Event handling control. + + virtual int deactivated (void); + // Return the status of Reactor. If this function returns 0, the reactor is + // actively handling events. If it returns non-zero, <handling_events> and + // <handle_alertable_events> return -1 immediately. + + virtual void deactivate (int do_stop); + // Control whether the Reactor will handle any more incoming events or not. + // If <do_stop> == 1, the Reactor will be disabled. By default, a reactor + // is in active state and can be deactivated/reactived as wish. + // = Register and remove Handlers. virtual int register_handler (ACE_Event_Handler *event_handler, @@ -1072,6 +1084,10 @@ protected: int open_for_business_; // This flag is used to keep track of whether we are already closed. + sig_atomic_t deactivated_; + // This flag is used to keep track of whether we are actively handling + // events or not. + private: ACE_WFMO_Reactor (const ACE_WFMO_Reactor &); ACE_WFMO_Reactor &operator = (const ACE_WFMO_Reactor &); diff --git a/ace/WFMO_Reactor.i b/ace/WFMO_Reactor.i index ec27a225fb6..3a4215119be 100644 --- a/ace/WFMO_Reactor.i +++ b/ace/WFMO_Reactor.i @@ -821,6 +821,19 @@ ACE_WFMO_Reactor::alertable_handle_events (ACE_Time_Value *how_long) } ACE_INLINE int +ACE_WFMO_Reactor::deactivated (void) +{ + return this->deactivated_; +} + +ACE_INLINE void +ACE_WFMO_Reactor::deactivate (int do_stop) +{ + this->deactivated_ = do_stop; + this->wakeup_all_threads (); +} + +ACE_INLINE int ACE_WFMO_Reactor::owner (ACE_thread_t *t) { ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1); |