Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends

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.

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


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.

  : handler_rep_ (*this)
  , timer_queue_ (0)
  , signal_handler_ (0)
  , notify_handler_ (0)
  , delete_timer_queue_ (false)
  , delete_signal_handler_ (false)
  , delete_notify_handler_ (false)
  , initialized_ (false)
  , restart_ (0)
  , requeue_position_ (-1) // Requeue at end of waiters by default.
  , state_changed_ (0)
  , mask_signals_ (ms)
  , supress_renew_ (0)
{
}

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.

Reimplemented in ACE_QtReactor.

Definition at line 991 of file Select_Reactor_Base.cpp.

{
  ACE_TRACE ("ACE_Select_Reactor_Impl::bit_ops");
  if (this->handler_rep_.handle_in_range (handle) == 0)
    return -1;

#if !defined (ACE_WIN32)
  ACE_Sig_Guard sb (0,
                    this->mask_signals_); // Block out all signals until method returns.
#endif /* ACE_WIN32 */

  ACE_FDS_PTMF ptmf  = &ACE_Handle_Set::set_bit;
  u_long omask = ACE_Event_Handler::NULL_MASK;

  // Find the old reactor masks.  This automatically does the work of
  // the GET_MASK operation.
  if (handle_set.rd_mask_.is_set (handle))
    ACE_SET_BITS (omask, ACE_Event_Handler::READ_MASK);
  if (handle_set.wr_mask_.is_set (handle))
    ACE_SET_BITS (omask, ACE_Event_Handler::WRITE_MASK);
  if (handle_set.ex_mask_.is_set (handle))
    ACE_SET_BITS (omask, ACE_Event_Handler::EXCEPT_MASK);

  switch (ops)
    {
    case ACE_Reactor::GET_MASK:
      // The work for this operation is done in all cases at the
      // begining of the function.
      break;
    case ACE_Reactor::CLR_MASK:
      ptmf = &ACE_Handle_Set::clr_bit;
      // State was changed. we need to reflect that change in the
      // dispatch_mask I assume that only ACE_Reactor::CLR_MASK should
      // be treated here  which means we need to clear the handle|mask
      // from the current dispatch handler
      this->clear_dispatch_mask (handle, mask);
      /* FALLTHRU */
    case ACE_Reactor::SET_MASK:
      /* FALLTHRU */
    case ACE_Reactor::ADD_MASK:

      // The following code is rather subtle...  Note that if we are
      // doing a ACE_Reactor::SET_MASK then if the bit is not enabled
      // in the mask we need to clear the bit from the ACE_Handle_Set.
      // On the other hand, if we are doing a ACE_Reactor::CLR_MASK or
      // a ACE_Reactor::ADD_MASK we just carry out the operations
      // specified by the mask.

      // READ, ACCEPT, and CONNECT flag will place the handle in the
      // read set.
      if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK)
          || ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK)
          || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
        {
          (handle_set.rd_mask_.*ptmf) (handle);
        }
      else if (ops == ACE_Reactor::SET_MASK)
        handle_set.rd_mask_.clr_bit (handle);

      // WRITE and CONNECT flag will place the handle in the write set
      if (ACE_BIT_ENABLED (mask,
                           ACE_Event_Handler::WRITE_MASK)
          || ACE_BIT_ENABLED (mask,
                              ACE_Event_Handler::CONNECT_MASK))
        {
          (handle_set.wr_mask_.*ptmf) (handle);
        }
      else if (ops == ACE_Reactor::SET_MASK)
        handle_set.wr_mask_.clr_bit (handle);

      // EXCEPT (and CONNECT on Win32) flag will place the handle in
      // the except set.
      if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK)
#if defined (ACE_WIN32)
          || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK)
#endif /* ACE_WIN32 */
          )
        {
          (handle_set.ex_mask_.*ptmf) (handle);
        }
      else if (ops == ACE_Reactor::SET_MASK)
        handle_set.ex_mask_.clr_bit (handle);
      break;
    default:
      return -1;
    }
  return omask;
}

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 1084 of file Select_Reactor_Base.cpp.

{
  ACE_TRACE ("ACE_Select_Reactor_Impl::clear_dispatch_mask");

  //  Use handle and mask in order to modify the sets
  // (wait/suspend/ready/dispatch), that way, the dispatch_io_set loop
  // will not be interrupt, and there will no reason to rescan the
  // wait_set and re-calling select function, which is *very*
  // expensive. It seems that wait/suspend/ready sets are getting
  // updated in register/remove bind/unbind etc functions.  The only
  // thing need to be updated is the dispatch_set (also can  be found
  // in that file code as dispatch_mask).  Because of that, we need
  // that dispatch_set to be member of the ACE_Select_Reactor_impl in
  // Select_Reactor_Base.h file  That way we will have access to that
  // member in that function.

  // We kind of invalidate the iterator in dispatch_io_set because its
  // an array and index built from the original dispatch-set. Take a
  // look at dispatch_io_set for more details.

  // We only need to clr_bit, because we are interested in clearing the
  // handles that was removed, so no dispatching to these handles will
  // occur.
  if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK) ||
      ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK))
    {
      this->dispatch_set_.rd_mask_.clr_bit (handle);
    }
  if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK))
    {
      this->dispatch_set_.wr_mask_.clr_bit (handle);
    }
  if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
    {
      this->dispatch_set_.ex_mask_.clr_bit (handle);
    }

  // That will make the dispatch_io_set iterator re-start and rescan
  // the dispatch set.
  this->state_changed_ = true;
}

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]
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 970 of file Select_Reactor_Base.cpp.

{
  if (this->notify_handler_ == 0)
    return 0;
  else
    return this->notify_handler_->purge_pending_notifications (eh, mask);
}

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 1129 of file Select_Reactor_Base.cpp.

{
  // The select reactor has no handlers that can be resumed by the
  // application. So return 0;

  return 0;
}

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

Definition at line 147 of file Select_Reactor_Base.inl.

{
  this->supress_renew_ = sr;
}

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.

{
  return this->supress_renew_;
}


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