NAME

ACE_TP_Reactor -

Specialization of Select Reactor to support thread-pool based event dispatching.

SYNOPSIS

#include <ace/TP_Reactor.h>

class ACE_TP_Reactor : public ACE_Select_Reactor { public: ACE_TP_Reactor (ACE_Sig_Handler * = 0, ACE_Timer_Queue * = 0); ACE_TP_Reactor ( size_t size, int restart = 0, ACE_Sig_Handler * = 0, ACE_Timer_Queue * = 0 ); virtual int handle_events (ACE_Time_Value *max_wait_time = 0); virtual int handle_events (ACE_Time_Value &max_wait_time); static void no_op_sleep_hook (void *); virtual void wakeup_all_threads (void); ACE_ALLOC_HOOK_DECLARE; protected: virtual int dispatch_io_set ( int number_of_active_handles, int& number_dispatched, int mask, ACE_Handle_Set& dispatch_mask, ACE_Handle_Set& ready_mask, ACE_EH_PTMF callback ); virtual void notify_handle ( ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Handle_Set &, ACE_Event_Handler *eh, ACE_EH_PTMF callback ); virtual int notify_handle (ACE_EH_Dispatch_Info &dispatch_info); ACE_EH_Dispatch_Info dispatch_info_; private: ACE_TP_Reactor (const ACE_TP_Reactor &); ACE_TP_Reactor &operator = (const ACE_TP_Reactor &); };

DESCRIPTION

One of the short comings of the Select_Reactor in ACE is that it did not support a thread pool based event dispatching model, similar to the one in WFMO_Reactor. In Select_Reactor, only thread can be blocked in handle_events() at any given time.

A new Reactor has been added to ACE that removes this short-coming. TP_Reactor is a specialization of 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 that just got activated, releasing the internal lock (so that some other thread can start waiting in the event loop) and then dispatching the event handler outside the context of the Reactor lock.

This Reactor 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 loops.

Note that callback code in Event Handlers (e.g. Event_Handler::handle_input) does not have to be modified or made thread-safe for this Reactor. This is because an activated Event Handler is suspended in the Reactor before the upcall is made and resumed after the upcall completes. Therefore, one Event Handler cannot be called by multiple threads simultaneously.

Initialization and termination methods.

ACE_TP_Reactor (ACE_Sig_Handler * = 0, ACE_Timer_Queue * = 0);

ACE_TP_Reactor (
    size_t size,
    int restart = 0,
    ACE_Sig_Handler * = 0,
    ACE_Timer_Queue * = 0
    );

Event loop drivers.

virtual int handle_events (ACE_Time_Value *max_wait_time = 0);

virtual int handle_events (ACE_Time_Value &max_wait_time);

static void no_op_sleep_hook (void *);

virtual void wakeup_all_threads (void);

ACE_ALLOC_HOOK_DECLARE;

Internal methods that do the actual work.

virtual int dispatch_io_set (
    int number_of_active_handles,
    int& number_dispatched,
    int mask,
    ACE_Handle_Set& dispatch_mask,
    ACE_Handle_Set& ready_mask,
    ACE_EH_PTMF callback
    );

virtual void notify_handle (
    ACE_HANDLE handle,
    ACE_Reactor_Mask mask,
    ACE_Handle_Set &,
    ACE_Event_Handler *eh,
    ACE_EH_PTMF callback
    );

virtual int notify_handle (ACE_EH_Dispatch_Info &dispatch_info);

ACE_EH_Dispatch_Info dispatch_info_;

AUTHOR

Irfan Pyarali

LIBRARY

ace