ACE_Select_Reactor_Impl Class Reference

This class simply defines how Select_Reactor's basic interface functions should look like and provides a common base class for Select_Reactor using various locking mechanism. More...

#include <Select_Reactor_Base.h>

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

List of all members.

Public Types

enum  { DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE }

Public Member Functions

 ACE_Select_Reactor_Impl (bool mask_signals=true)
 Constructor.
virtual int purge_pending_notifications (ACE_Event_Handler *=0, ACE_Reactor_Mask=ACE_Event_Handler::ALL_EVENTS_MASK)
virtual int resumable_handler (void)

Protected Member Functions

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.
virtual void renew (void)=0
virtual int is_suspended_i (ACE_HANDLE handle)=0
virtual void clear_dispatch_mask (ACE_HANDLE handle, ACE_Reactor_Mask mask)
int supress_notify_renew (void)
void supress_notify_renew (int sr)

Protected Attributes

ACE_Select_Reactor_Handler_Repository handler_rep_
 Table that maps <ACE_HANDLEs> to <ACE_Event_Handler *>'s.
ACE_Select_Reactor_Handle_Set dispatch_set_
 Tracks handles that are ready for dispatch from <select>.
ACE_Select_Reactor_Handle_Set wait_set_
 Tracks handles that are waited for by <select>.
ACE_Select_Reactor_Handle_Set suspend_set_
 Tracks handles that are currently suspended.
ACE_Select_Reactor_Handle_Set ready_set_
ACE_Timer_Queuetimer_queue_
 Defined as a pointer to allow overriding by derived classes...
ACE_Sig_Handlersignal_handler_
 Handle signals without requiring global/static variables.
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...
bool restart_
int requeue_position_
ACE_thread_t owner_
 The original thread that created this Select_Reactor.
bool state_changed_
bool mask_signals_

Private Member Functions

 ACE_Select_Reactor_Impl (const ACE_Select_Reactor_Impl &)
 Deny access since member-wise won't work...
ACE_Select_Reactor_Imploperator= (const ACE_Select_Reactor_Impl &)

Private Attributes

int supress_renew_

Friends

class ACE_Select_Reactor_Notify
class ACE_Select_Reactor_Handler_Repository

Detailed Description

This class simply defines how Select_Reactor's basic interface functions should look like and provides a common base class for Select_Reactor using various locking mechanism.

Definition at line 463 of file Select_Reactor_Base.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
DEFAULT_SIZE 

Default size of the Select_Reactor's handle table.

Definition at line 466 of file Select_Reactor_Base.h.

00467   {
00468     /// Default size of the Select_Reactor's handle table.
00469     DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE
00470   };


Constructor & Destructor Documentation

ACE_Select_Reactor_Impl::ACE_Select_Reactor_Impl ( bool  mask_signals = true  ) 

Constructor.

Definition at line 120 of file Select_Reactor_Base.inl.

00121   : handler_rep_ (*this)
00122   , timer_queue_ (0)
00123   , signal_handler_ (0)
00124   , notify_handler_ (0)
00125   , delete_timer_queue_ (false)
00126   , delete_signal_handler_ (false)
00127   , delete_notify_handler_ (false)
00128   , initialized_ (false)
00129   , restart_ (0)
00130   , requeue_position_ (-1) // Requeue at end of waiters by default.
00131   , state_changed_ (0)
00132   , mask_signals_ (ms)
00133   , supress_renew_ (0)
00134 {
00135 }

ACE_Select_Reactor_Impl::ACE_Select_Reactor_Impl ( const ACE_Select_Reactor_Impl  )  [private]

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


Member Function Documentation

int ACE_Select_Reactor_Impl::bit_ops ( ACE_HANDLE  handle,
ACE_Reactor_Mask  mask,
ACE_Select_Reactor_Handle_Set handle_set,
int  ops 
) [protected, virtual]

Allow manipulation of the <wait_set_> mask and <ready_set_> mask.

Definition at line 987 of file Select_Reactor_Base.cpp.

00991 {
00992   ACE_TRACE ("ACE_Select_Reactor_Impl::bit_ops");
00993   if (this->handler_rep_.handle_in_range (handle) == 0)
00994     return -1;
00995 
00996 #if !defined (ACE_WIN32)
00997   ACE_Sig_Guard sb (0,
00998                     this->mask_signals_); // Block out all signals until method returns.
00999 #endif /* ACE_WIN32 */
01000 
01001   ACE_FDS_PTMF ptmf  = &ACE_Handle_Set::set_bit;
01002   u_long omask = ACE_Event_Handler::NULL_MASK;
01003 
01004   // Find the old reactor masks.  This automatically does the work of
01005   // the GET_MASK operation.
01006   if (handle_set.rd_mask_.is_set (handle))
01007     ACE_SET_BITS (omask, ACE_Event_Handler::READ_MASK);
01008   if (handle_set.wr_mask_.is_set (handle))
01009     ACE_SET_BITS (omask, ACE_Event_Handler::WRITE_MASK);
01010   if (handle_set.ex_mask_.is_set (handle))
01011     ACE_SET_BITS (omask, ACE_Event_Handler::EXCEPT_MASK);
01012 
01013   switch (ops)
01014     {
01015     case ACE_Reactor::GET_MASK:
01016       // The work for this operation is done in all cases at the
01017       // begining of the function.
01018       break;
01019     case ACE_Reactor::CLR_MASK:
01020       ptmf = &ACE_Handle_Set::clr_bit;
01021       // State was changed. we need to reflect that change in the
01022       // dispatch_mask I assume that only ACE_Reactor::CLR_MASK should
01023       // be treated here  which means we need to clear the handle|mask
01024       // from the current dispatch handler
01025       this->clear_dispatch_mask (handle, mask);
01026       /* FALLTHRU */
01027     case ACE_Reactor::SET_MASK:
01028       /* FALLTHRU */
01029     case ACE_Reactor::ADD_MASK:
01030 
01031       // The following code is rather subtle...  Note that if we are
01032       // doing a ACE_Reactor::SET_MASK then if the bit is not enabled
01033       // in the mask we need to clear the bit from the ACE_Handle_Set.
01034       // On the other hand, if we are doing a ACE_Reactor::CLR_MASK or
01035       // a ACE_Reactor::ADD_MASK we just carry out the operations
01036       // specified by the mask.
01037 
01038       // READ, ACCEPT, and CONNECT flag will place the handle in the
01039       // read set.
01040       if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK)
01041           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK)
01042           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
01043         {
01044           (handle_set.rd_mask_.*ptmf) (handle);
01045         }
01046       else if (ops == ACE_Reactor::SET_MASK)
01047         handle_set.rd_mask_.clr_bit (handle);
01048 
01049       // WRITE and CONNECT flag will place the handle in the write set
01050       if (ACE_BIT_ENABLED (mask,
01051                            ACE_Event_Handler::WRITE_MASK)
01052           || ACE_BIT_ENABLED (mask,
01053                               ACE_Event_Handler::CONNECT_MASK))
01054         {
01055           (handle_set.wr_mask_.*ptmf) (handle);
01056         }
01057       else if (ops == ACE_Reactor::SET_MASK)
01058         handle_set.wr_mask_.clr_bit (handle);
01059 
01060       // EXCEPT (and CONNECT on Win32) flag will place the handle in
01061       // the except set.
01062       if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK)
01063 #if defined (ACE_WIN32)
01064           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK)
01065 #endif /* ACE_WIN32 */
01066           )
01067         {
01068           (handle_set.ex_mask_.*ptmf) (handle);
01069         }
01070       else if (ops == ACE_Reactor::SET_MASK)
01071         handle_set.ex_mask_.clr_bit (handle);
01072       break;
01073     default:
01074       return -1;
01075     }
01076   return omask;
01077 }

void ACE_Select_Reactor_Impl::clear_dispatch_mask ( ACE_HANDLE  handle,
ACE_Reactor_Mask  mask 
) [protected, virtual]

When register/unregister occur, then we need to re-eval our wait/suspend/dispatch set.

Reimplemented in ACE_TP_Reactor.

Definition at line 1080 of file Select_Reactor_Base.cpp.

01082 {
01083   ACE_TRACE ("ACE_Select_Reactor_Impl::clear_dispatch_mask");
01084 
01085   //  Use handle and mask in order to modify the sets
01086   // (wait/suspend/ready/dispatch), that way, the dispatch_io_set loop
01087   // will not be interrupt, and there will no reason to rescan the
01088   // wait_set and re-calling select function, which is *very*
01089   // expensive. It seems that wait/suspend/ready sets are getting
01090   // updated in register/remove bind/unbind etc functions.  The only
01091   // thing need to be updated is the dispatch_set (also can  be found
01092   // in that file code as dispatch_mask).  Because of that, we need
01093   // that dispatch_set to be member of the ACE_Select_Reactor_impl in
01094   // Select_Reactor_Base.h file  That way we will have access to that
01095   // member in that function.
01096 
01097   // We kind of invalidate the iterator in dispatch_io_set because its
01098   // an array and index built from the original dispatch-set. Take a
01099   // look at dispatch_io_set for more details.
01100 
01101   // We only need to clr_bit, because we are interested in clearing the
01102   // handles that was removed, so no dispatching to these handles will
01103   // occur.
01104   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK) ||
01105       ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK))
01106     {
01107       this->dispatch_set_.rd_mask_.clr_bit (handle);
01108     }
01109   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK))
01110     {
01111       this->dispatch_set_.wr_mask_.clr_bit (handle);
01112     }
01113   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
01114     {
01115       this->dispatch_set_.ex_mask_.clr_bit (handle);
01116     }
01117 
01118   // That will make the dispatch_io_set iterator re-start and rescan
01119   // the dispatch set.
01120   this->state_changed_ = true;
01121 }

virtual int ACE_Select_Reactor_Impl::is_suspended_i ( ACE_HANDLE  handle  )  [protected, pure virtual]

Check to see if the Event_Handler associated with handle is suspended. Returns 0 if not, 1 if so.

Implemented in ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

ACE_Select_Reactor_Impl& ACE_Select_Reactor_Impl::operator= ( const ACE_Select_Reactor_Impl  )  [private]

Reimplemented in ACE_Priority_Reactor, and ACE_TP_Reactor.

int ACE_Select_Reactor_Impl::purge_pending_notifications ( ACE_Event_Handler eh = 0,
ACE_Reactor_Mask  mask = ACE_Event_Handler::ALL_EVENTS_MASK 
) [virtual]

Purge any notifications pending in this reactor for the specified ACE_Event_Handler object. Returns the number of notifications purged. Returns -1 on error.

Implements ACE_Reactor_Impl.

Definition at line 966 of file Select_Reactor_Base.cpp.

00968 {
00969   if (this->notify_handler_ == 0)
00970     return 0;
00971   else
00972     return this->notify_handler_->purge_pending_notifications (eh, mask);
00973 }

virtual void ACE_Select_Reactor_Impl::renew ( void   )  [protected, pure virtual]

Enqueue ourselves into the list of waiting threads at the appropriate point specified by <requeue_position_>.

Implemented in ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

int ACE_Select_Reactor_Impl::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 select reactor has no handlers that can be resumed by the application. So return 0;

Implements ACE_Reactor_Impl.

Reimplemented in ACE_TP_Reactor.

Definition at line 1125 of file Select_Reactor_Base.cpp.

01126 {
01127   // The select reactor has no handlers that can be resumed by the
01128   // application. So return 0;
01129 
01130   return 0;
01131 }

void ACE_Select_Reactor_Impl::supress_notify_renew ( int  sr  )  [protected]

Definition at line 147 of file Select_Reactor_Base.inl.

00148 {
00149   this->supress_renew_ = sr;
00150 }

int ACE_Select_Reactor_Impl::supress_notify_renew ( void   )  [protected]

Controls/access whether the notify handler should renew the Select_Reactor's token or not.

Definition at line 141 of file Select_Reactor_Base.inl.

00142 {
00143   return this->supress_renew_;
00144 }


Friends And Related Function Documentation

Definition at line 476 of file Select_Reactor_Base.h.

friend class ACE_Select_Reactor_Notify [friend]

Definition at line 475 of file Select_Reactor_Base.h.


Member Data Documentation

Keeps track of whether we need to delete the notify handler (if we didn't create it, then we don't delete it).

Definition at line 555 of file Select_Reactor_Base.h.

Keeps track of whether we should delete the signal handler (if we didn't create it, then we don't delete it).

Definition at line 551 of file Select_Reactor_Base.h.

Keeps track of whether we should delete the timer queue (if we didn't create it, then we don't delete it).

Definition at line 547 of file Select_Reactor_Base.h.

Tracks handles that are ready for dispatch from <select>.

Definition at line 523 of file Select_Reactor_Base.h.

Table that maps <ACE_HANDLEs> to <ACE_Event_Handler *>'s.

Definition at line 520 of file Select_Reactor_Base.h.

True if we've been initialized yet...

Definition at line 558 of file Select_Reactor_Base.h.

If false then the Reactor will not mask the signals during the event dispatching. This is useful for applications that do not register any signal handlers and want to reduce the overhead introduce by the kernel level locks required to change the mask.

Definition at line 590 of file Select_Reactor_Base.h.

Callback object that unblocks the ACE_Select_Reactor if it's sleeping.

Definition at line 543 of file Select_Reactor_Base.h.

The original thread that created this Select_Reactor.

Definition at line 574 of file Select_Reactor_Base.h.

Track HANDLES we are interested in for various events that must be dispatched *without* going through <select>.

Definition at line 533 of file Select_Reactor_Base.h.

Position that the main ACE_Select_Reactor thread is requeued in the list of waiters during a <notify> callback. If this value == -1 we are requeued at the end of the list. Else if it's 0 then we are requeued at the front of the list. Else if it's > 1 then that indicates the number of waiters to skip over.

Definition at line 571 of file Select_Reactor_Base.h.

Restart the <handle_events> event-loop method automatically when <select> is interrupted via <EINTR>.

Definition at line 562 of file Select_Reactor_Base.h.

Handle signals without requiring global/static variables.

Definition at line 539 of file Select_Reactor_Base.h.

True if state has changed during dispatching of ACE_Event_Handlers, else false. This is used to determine whether we need to make another trip through the <Select_Reactor>'s <wait_for_multiple_events> loop.

Definition at line 582 of file Select_Reactor_Base.h.

Determine whether we should renew Select_Reactor's token after handling the notification message.

Definition at line 601 of file Select_Reactor_Base.h.

Tracks handles that are currently suspended.

Definition at line 529 of file Select_Reactor_Base.h.

Defined as a pointer to allow overriding by derived classes...

Definition at line 536 of file Select_Reactor_Base.h.

Tracks handles that are waited for by <select>.

Definition at line 526 of file Select_Reactor_Base.h.


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

Generated on Sat Nov 21 23:17:57 2009 for ACE by  doxygen 1.6.1