ACE  6.4.2
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | List of all members
ACE_TP_Reactor Class Reference

Specialization of ACE_Select_Reactor to support thread-pool based event dispatching. More...

#include <TP_Reactor.h>

Inheritance diagram for ACE_TP_Reactor:
Inheritance graph
[legend]
Collaboration diagram for ACE_TP_Reactor:
Collaboration graph
[legend]

Public Member Functions

 ACE_TP_Reactor (ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, bool mask_signals=true, int s_queue=ACE_Select_Reactor_Token::FIFO)
 Initialize ACE_TP_Reactor with the default size. More...
 
 ACE_TP_Reactor (size_t max_number_of_handles, bool restart=false, ACE_Sig_Handler *sh=0, ACE_Timer_Queue *tq=0, bool mask_signals=true, int s_queue=ACE_Select_Reactor_Token::FIFO)
 
virtual int handle_events (ACE_Time_Value *max_wait_time=0)
 
virtual int handle_events (ACE_Time_Value &max_wait_time)
 
virtual int resumable_handler (void)
 
virtual int owner (ACE_thread_t n_id, ACE_thread_t *o_id=0)
 
virtual int owner (ACE_thread_t *t_id)
 Return the thread ID of the current Leader. More...
 
- Public Member Functions inherited from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >
 ACE_Select_Reactor_T (ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=ACE_DISABLE_NOTIFY_PIPE_DEFAULT, ACE_Reactor_Notify *notify=0, bool mask_signals=true, int s_queue=ACE_SELECT_TOKEN::FIFO)
 
 ACE_Select_Reactor_T (size_t size, bool restart=false, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=ACE_DISABLE_NOTIFY_PIPE_DEFAULT, ACE_Reactor_Notify *notify=0, bool mask_signals=true, int s_queue=ACE_SELECT_TOKEN::FIFO)
 
virtual int open (size_t max_number_of_handles=DEFAULT_SIZE, bool restart=false, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=ACE_DISABLE_NOTIFY_PIPE_DEFAULT, ACE_Reactor_Notify *=0)
 
virtual int current_info (ACE_HANDLE, size_t &size)
 Returns -1 (not used in this implementation);. More...
 
virtual int set_sig_handler (ACE_Sig_Handler *signal_handler)
 Use a user specified signal handler instead. More...
 
virtual int timer_queue (ACE_Timer_Queue *tq)
 Set a user-specified timer queue. More...
 
virtual ACE_Timer_Queuetimer_queue (void) const
 Return the current ACE_Timer_Queue. More...
 
virtual int close (void)
 Close down the select_reactor and release all of its resources. More...
 
virtual ~ACE_Select_Reactor_T (void)
 Close down the select_reactor and release all of its resources. More...
 
virtual int work_pending (const ACE_Time_Value &max_wait_time=ACE_Time_Value::zero)
 
virtual int deactivated (void)
 
virtual void deactivate (int do_stop)
 
virtual int register_handler (ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 
virtual int register_handler (ACE_HANDLE handle, ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 
virtual int register_handler (ACE_Event_Handler *event_handler, ACE_HANDLE event_handle=ACE_INVALID_HANDLE)
 Not implemented. More...
 
virtual int register_handler (ACE_HANDLE event_handle, ACE_HANDLE io_handle, ACE_Event_Handler *event_handler, ACE_Reactor_Mask mask)
 Not implemented. More...
 
virtual int register_handler (const ACE_Handle_Set &handles, ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 Register eh with all the handles in the <Handle_Set>. More...
 
virtual int register_handler (int signum, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp=0, ACE_Event_Handler **old_sh=0, ACE_Sig_Action *old_disp=0)
 
virtual int register_handler (const ACE_Sig_Set &sigset, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp=0)
 
virtual int remove_handler (ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 
virtual int remove_handler (ACE_HANDLE handle, ACE_Reactor_Mask)
 
virtual int remove_handler (const ACE_Handle_Set &handle_set, ACE_Reactor_Mask)
 
virtual int remove_handler (int signum, ACE_Sig_Action *new_disp, ACE_Sig_Action *old_disp=0, int sigkey=-1)
 
virtual int remove_handler (const ACE_Sig_Set &sigset)
 Calls <remove_handler> for every signal in sigset. More...
 
virtual int suspend_handler (ACE_Event_Handler *eh)
 Temporarily suspend the <Event_Handler> associated with eh. More...
 
virtual int suspend_handler (ACE_HANDLE handle)
 Temporarily suspend the Event_Handler associated with handle. More...
 
virtual int suspend_handler (const ACE_Handle_Set &handles)
 Suspend all handles in handle set temporarily. More...
 
virtual int suspend_handlers (void)
 Suspend all the <Event_Handlers> in the Select_Reactor. More...
 
virtual int resume_handler (ACE_Event_Handler *eh)
 
virtual int resume_handler (ACE_HANDLE handle)
 
virtual int resume_handler (const ACE_Handle_Set &handles)
 Resume all handles in handle set. More...
 
virtual int resume_handlers (void)
 Resume all the <Event_Handlers> in the Select_Reactor. More...
 
virtual bool uses_event_associations (void)
 
virtual long schedule_timer (ACE_Event_Handler *event_handler, const void *arg, const ACE_Time_Value &delay, const ACE_Time_Value &interval=ACE_Time_Value::zero)
 
virtual int reset_timer_interval (long timer_id, const ACE_Time_Value &interval)
 
virtual int cancel_timer (ACE_Event_Handler *event_handler, int dont_call_handle_close=1)
 
virtual int cancel_timer (long timer_id, const void **arg=0, int dont_call_handle_close=1)
 
virtual int schedule_wakeup (ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 ADD the dispatch MASK "bit" bound with the eh and the mask. More...
 
virtual int schedule_wakeup (ACE_HANDLE handle, ACE_Reactor_Mask mask)
 ADD the dispatch MASK "bit" bound with the handle and the mask. More...
 
virtual int cancel_wakeup (ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 CLR the dispatch MASK "bit" bound with the eh and the mask. More...
 
virtual int cancel_wakeup (ACE_HANDLE handle, ACE_Reactor_Mask mask)
 CLR the dispatch MASK "bit" bound with the handle and the mask. More...
 
virtual int notify (ACE_Event_Handler *=0, ACE_Reactor_Mask=ACE_Event_Handler::EXCEPT_MASK, ACE_Time_Value *=0)
 
virtual void max_notify_iterations (int)
 
virtual int max_notify_iterations (void)
 
virtual bool restart (void)
 Get the existing restart value. More...
 
virtual bool restart (bool r)
 Set a new value for restart and return the original value. More...
 
virtual void requeue_position (int)
 
virtual int requeue_position (void)
 
virtual int mask_ops (ACE_Event_Handler *eh, ACE_Reactor_Mask mask, int ops)
 
virtual int mask_ops (ACE_HANDLE handle, ACE_Reactor_Mask mask, int ops)
 
virtual int ready_ops (ACE_Event_Handler *eh, ACE_Reactor_Mask mask, int ops)
 GET/SET/ADD/CLR the ready "bit" bound with the eh and mask. More...
 
virtual int ready_ops (ACE_HANDLE handle, ACE_Reactor_Mask, int ops)
 GET/SET/ADD/CLR the ready "bit" bound with the handle and mask. More...
 
virtual void wakeup_all_threads (void)
 Wake up all threads in waiting in the event loop. More...
 
virtual ACE_Event_Handlerfind_handler (ACE_HANDLE handle)
 
virtual int handler (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Event_Handler **eh=0)
 
virtual int handler (int signum, ACE_Event_Handler **=0)
 
virtual bool initialized (void)
 Returns true if we've been successfully initialized, else false. More...
 
virtual size_t size (void) const
 
virtual ACE_Locklock (void)
 
virtual void dump (void) const
 Dump the state of an object. More...
 
virtual int alertable_handle_events (ACE_Time_Value *max_wait_time=0)
 
virtual int alertable_handle_events (ACE_Time_Value &max_wait_time)
 
- Public Member Functions inherited from ACE_Select_Reactor_Impl
 ACE_Select_Reactor_Impl (bool mask_signals=true)
 Constructor. More...
 
virtual int purge_pending_notifications (ACE_Event_Handler *=0, ACE_Reactor_Mask=ACE_Event_Handler::ALL_EVENTS_MASK)
 
- Public Member Functions inherited from ACE_Reactor_Impl
virtual ~ACE_Reactor_Impl (void)
 Close down and release all resources. More...
 

Static Public Member Functions

static void no_op_sleep_hook (void *)
 Called from handle events. More...
 

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...
 
- Public Attributes inherited from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >
 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...
 
- Public Attributes inherited from ACE_Reactor_Impl
 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...
 

Protected Member Functions

virtual void clear_dispatch_mask (ACE_HANDLE handle, ACE_Reactor_Mask mask)
 Template method from the base class. More...
 
int dispatch_i (ACE_Time_Value *max_wait_time, ACE_TP_Token_Guard &guard)
 Dispatch just 1 signal, timer, notification handlers. More...
 
int get_event_for_dispatching (ACE_Time_Value *max_wait_time)
 
int handle_timer_events (int &event_count, ACE_TP_Token_Guard &g)
 Handle timer events. More...
 
int handle_notify_events (int &event_count, ACE_TP_Token_Guard &g)
 Handle notify events. More...
 
int handle_socket_events (int &event_count, ACE_TP_Token_Guard &g)
 handle socket events More...
 
virtual void notify_handle (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Handle_Set &, ACE_Event_Handler *eh, ACE_EH_PTMF callback)
 This method shouldn't get called. More...
 
- Protected Member Functions inherited from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >
virtual int register_handler_i (ACE_HANDLE handle, ACE_Event_Handler *eh, ACE_Reactor_Mask mask)
 
virtual int register_handler_i (const ACE_Handle_Set &handles, ACE_Event_Handler *handler, ACE_Reactor_Mask mask)
 Register a set of handles. More...
 
virtual int remove_handler_i (ACE_HANDLE handle, ACE_Reactor_Mask)
 
virtual int remove_handler_i (const ACE_Handle_Set &handles, ACE_Reactor_Mask)
 Remove a set of handles. More...
 
virtual int suspend_i (ACE_HANDLE handle)
 Suspend the <Event_Handler> associated with handle. More...
 
virtual int is_suspended_i (ACE_HANDLE handle)
 
virtual int resume_i (ACE_HANDLE handle)
 Resume the <Event_Handler> associated with handle. More...
 
virtual ACE_Event_Handlerfind_handler_i (ACE_HANDLE handle)
 Implement the public handler method. More...
 
virtual int handler_i (ACE_HANDLE handle, ACE_Reactor_Mask, ACE_Event_Handler **=0)
 Implement the public handler method. More...
 
virtual int handler_i (int signum, ACE_Event_Handler **=0)
 Implement the public handler method. More...
 
virtual int any_ready (ACE_Select_Reactor_Handle_Set &handle_set)
 
virtual int any_ready_i (ACE_Select_Reactor_Handle_Set &handle_set)
 
virtual int handle_error (void)
 Take corrective action when errors occur. More...
 
virtual int check_handles (void)
 Make sure the handles are all valid. More...
 
virtual int wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &, ACE_Time_Value *)
 Wait for events to occur. More...
 
virtual int dispatch (int nfound, ACE_Select_Reactor_Handle_Set &)
 
virtual int dispatch_timer_handlers (int &number_dispatched)
 
virtual int dispatch_notification_handlers (ACE_Select_Reactor_Handle_Set &dispatch_set, int &number_of_active_handles, int &number_of_handlers_dispatched)
 
virtual int dispatch_io_handlers (ACE_Select_Reactor_Handle_Set &dispatch_set, int &number_of_active_handles, int &number_of_handlers_dispatched)
 
virtual int dispatch_io_set (int number_of_active_handles, int &number_of_handlers_dispatched, int mask, ACE_Handle_Set &dispatch_mask, ACE_Handle_Set &ready_mask, ACE_EH_PTMF callback)
 
virtual void renew (void)
 
int release_token (void)
 Release the token lock when a Win32 structured exception occurs. More...
 
int handle_events_i (ACE_Time_Value *max_wait_time=0)
 Stops the VC++ compiler from bitching about exceptions and destructors. More...
 
- Protected Member Functions inherited from ACE_Select_Reactor_Impl
virtual int bit_ops (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Select_Reactor_Handle_Set &handle_set, int ops)
 Allow manipulation of the <wait_set_> mask and <ready_set_> mask. More...
 
int supress_notify_renew (void)
 
void supress_notify_renew (int sr)
 

Private Member Functions

ACE_HANDLE get_notify_handle (void)
 
int get_socket_event_info (ACE_EH_Dispatch_Info &info)
 Get socket event dispatch information. More...
 
int dispatch_socket_event (ACE_EH_Dispatch_Info &dispatch_info)
 
void clear_handle_read_set (ACE_HANDLE handle)
 Clear the handle from the read_set. More...
 
int post_process_socket_event (ACE_EH_Dispatch_Info &dispatch_info, int status)
 
 ACE_TP_Reactor (const ACE_TP_Reactor &)
 Deny access since member-wise won't work... More...
 
ACE_TP_Reactoroperator= (const ACE_TP_Reactor &)
 

Additional Inherited Members

- Public Types inherited from ACE_Select_Reactor_Impl
enum  { DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE }
 
- Protected Attributes inherited from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >
ACE_Select_Reactor_Token token_
 Synchronization token for the MT_SAFE ACE_Select_Reactor. More...
 
ACE_Lock_Adapter< ACE_Select_Reactor_Tokenlock_adapter_
 Adapter used to return internal lock to outside world. More...
 
sig_atomic_t deactivated_
 
- Protected Attributes inherited from ACE_Select_Reactor_Impl
ACE_Select_Reactor_Handler_Repository handler_rep_
 Table that maps <ACE_HANDLEs> to <ACE_Event_Handler *>'s. More...
 
ACE_Select_Reactor_Handle_Set dispatch_set_
 Tracks handles that are ready for dispatch from <select> More...
 
ACE_Select_Reactor_Handle_Set wait_set_
 Tracks handles that are waited for by <select>. More...
 
ACE_Select_Reactor_Handle_Set suspend_set_
 Tracks handles that are currently suspended. More...
 
ACE_Select_Reactor_Handle_Set ready_set_
 
ACE_Timer_Queuetimer_queue_
 Defined as a pointer to allow overriding by derived classes... More...
 
ACE_Sig_Handlersignal_handler_
 Handle signals without requiring global/static variables. More...
 
ACE_Reactor_Notifynotify_handler_
 
bool delete_timer_queue_
 
bool delete_signal_handler_
 
bool delete_notify_handler_
 
bool initialized_
 True if we've been initialized yet... More...
 
bool restart_
 
int requeue_position_
 
ACE_thread_t owner_
 The original thread that created this Select_Reactor. More...
 
bool state_changed_
 
bool mask_signals_
 

Detailed Description

Specialization of ACE_Select_Reactor to support thread-pool based event dispatching.

One of the shortcomings of the ACE_Select_Reactor is that it does not support a thread pool-based event dispatching model, similar to the one in ACE_WFMO_Reactor. In ACE_Select_Reactor, only thread can call handle_events() at any given time. ACE_TP_Reactor removes this short-coming.

ACE_TP_Reactor is a specialization of ACE_Select_Reactor to support thread pool-based event dispatching. This reactor takes advantage of the fact that events reported by select() are persistent if not acted upon immediately. It works by remembering the event handler which was just activated, suspending it for further I/O activities, releasing the internal lock (so that another thread can start waiting in the event loop) and then dispatching the event's handler outside the scope of the reactor lock. After the event handler has been dispatched the event handler is resumed for further I/O activity.

This reactor implementation is best suited for situations when the callbacks to event handlers can take arbitrarily long and/or a number of threads are available to run the event loop. Note that I/O-processing callback code in event handlers (e.g. handle_input()) does not have to be modified or made thread-safe for this reactor. This is because before an I/O event is dispatched to an event handler, the handler is suspended; it is resumed by the reactor after the upcall completes. Therefore, multiple I/O events will not be made to one event handler multiple threads simultaneously. This suspend/resume protection does not apply to either timers scheduled with the reactor or to notifications requested via the reactor. When using timers and/or notifications you must provide proper protection for your class in the context of multiple threads.

Constructor & Destructor Documentation

ACE_TP_Reactor::ACE_TP_Reactor ( ACE_Sig_Handler sh = 0,
ACE_Timer_Queue tq = 0,
bool  mask_signals = true,
int  s_queue = ACE_Select_Reactor_Token::FIFO 
)

Initialize ACE_TP_Reactor with the default size.

ACE_TP_Reactor::ACE_TP_Reactor ( size_t  max_number_of_handles,
bool  restart = false,
ACE_Sig_Handler sh = 0,
ACE_Timer_Queue tq = 0,
bool  mask_signals = true,
int  s_queue = ACE_Select_Reactor_Token::FIFO 
)

Initialize the ACE_TP_Reactor to manage max_number_of_handles. If restart is non-0 then the ACE_Reactor's handle_events() method will be restarted automatically when EINTR occurs. If sh or tq are non-0 they are used as the signal handler and timer queue, respectively.

ACE_TP_Reactor::ACE_TP_Reactor ( const ACE_TP_Reactor )
private

Deny access since member-wise won't work...

Member Function Documentation

void ACE_TP_Reactor::clear_dispatch_mask ( ACE_HANDLE  handle,
ACE_Reactor_Mask  mask 
)
inlineprotectedvirtual

Template method from the base class.

Reimplemented from ACE_Select_Reactor_Impl.

void ACE_TP_Reactor::clear_handle_read_set ( ACE_HANDLE  handle)
inlineprivate

Clear the handle from the read_set.

int ACE_TP_Reactor::dispatch_i ( ACE_Time_Value max_wait_time,
ACE_TP_Token_Guard guard 
)
protected

Dispatch just 1 signal, timer, notification handlers.

int ACE_TP_Reactor::dispatch_socket_event ( ACE_EH_Dispatch_Info dispatch_info)
private

Notify the appropriate <callback> in the context of the <eh> associated with <handle> that a particular event has occurred.

int ACE_TP_Reactor::get_event_for_dispatching ( ACE_Time_Value max_wait_time)
protected

Get the event that needs dispatching. It could be either a signal, timer, notification handlers or return possibly 1 I/O handler for dispatching. In the most common use case, this would return 1 I/O handler for dispatching

ACE_HANDLE ACE_TP_Reactor::get_notify_handle ( void  )
private

Get the handle of the notify pipe from the ready set if there is an event in the notify pipe.

int ACE_TP_Reactor::get_socket_event_info ( ACE_EH_Dispatch_Info info)
private

Get socket event dispatch information.

int ACE_TP_Reactor::handle_events ( ACE_Time_Value max_wait_time = 0)
virtual

This event loop driver that blocks for max_wait_time before returning. It will return earlier if timer events, I/O events, or signal events occur. Note that max_wait_time can be 0, in which case this method blocks indefinitely until events occur.

max_wait_time is decremented to reflect how much time this call took. For instance, if a time value of 3 seconds is passed to handle_events and an event occurs after 2 seconds, max_wait_time will equal 1 second. This can be used if an application wishes to handle events for some fixed amount of time.

Returns
The total number of events that were dispatched; 0 if the max_wait_time elapsed without dispatching any handlers, or -1 if an error occurs (check errno for more information).

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

int ACE_TP_Reactor::handle_events ( ACE_Time_Value max_wait_time)
virtual

This method is just like the one above, except the max_wait_time value is a reference and can therefore never be NULL.

Current <alertable_handle_events> is identical to <handle_events>.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

int ACE_TP_Reactor::handle_notify_events ( int &  event_count,
ACE_TP_Token_Guard g 
)
protected

Handle notify events.

int ACE_TP_Reactor::handle_socket_events ( int &  event_count,
ACE_TP_Token_Guard g 
)
protected

handle socket events

int ACE_TP_Reactor::handle_timer_events ( int &  event_count,
ACE_TP_Token_Guard g 
)
protected

Handle timer events.

void ACE_TP_Reactor::no_op_sleep_hook ( void *  )
inlinestatic

Called from handle events.

void ACE_TP_Reactor::notify_handle ( ACE_HANDLE  handle,
ACE_Reactor_Mask  mask,
ACE_Handle_Set ,
ACE_Event_Handler eh,
ACE_EH_PTMF  callback 
)
protectedvirtual

This method shouldn't get called.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

ACE_TP_Reactor& ACE_TP_Reactor::operator= ( const ACE_TP_Reactor )
private
int ACE_TP_Reactor::owner ( ACE_thread_t  n_id,
ACE_thread_t o_id = 0 
)
virtual

The ACE_TP_Reactor implementation does not have a single owner thread. Attempts to set the owner explicitly are ignored. The reported owner thread is the current Leader in the pattern.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

int ACE_TP_Reactor::owner ( ACE_thread_t t_id)
virtual

Return the thread ID of the current Leader.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

int ACE_TP_Reactor::post_process_socket_event ( ACE_EH_Dispatch_Info dispatch_info,
int  status 
)
private
int ACE_TP_Reactor::resumable_handler ( void  )
virtual

Does the reactor allow the application to resume the handle on its own ie. can it pass on the control of handle resumption to the application. The TP reactor has can allow applications to resume handles. So return a positive value.

Reimplemented from ACE_Select_Reactor_Impl.

Member Data Documentation

ACE_TP_Reactor::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.


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