#include <Priority_Reactor.h>
Inheritance diagram for ACE_Priority_Reactor:


Public Member Functions | |
| ACE_Priority_Reactor (ACE_Sig_Handler *=0, ACE_Timer_Queue *=0) | |
| Initialize  with the default size.   | |
| ACE_Priority_Reactor (size_t size, int restart=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0) | |
| Initialize  with size .   | |
| virtual | ~ACE_Priority_Reactor (void) | 
| Close down the select_reactor and release all of its resources.   | |
| void | dump (void) const | 
| Dump the state of an object.   | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks.   | |
Protected Member Functions | |
| 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) | 
Private Types | |
| typedef ACE_Unbounded_Queue< ACE_Event_Tuple >  | QUEUE | 
Private Member Functions | |
| void | init_bucket (void) | 
| A small helper to initialize the bucket.   | |
| void | build_bucket (ACE_Handle_Set &dispatch_mask, int &min_priority, int &max_priority) | 
| Build the bucket from the given dispatch_mask.   | |
| ACE_Priority_Reactor (const ACE_Priority_Reactor &) | |
| Deny access since member-wise won't work...   | |
| ACE_Priority_Reactor & | operator= (const ACE_Priority_Reactor &) | 
Private Attributes | |
| QUEUE ** | bucket_ | 
| ACE_Allocator * | tuple_allocator_ | 
This class refines the dispatching mechanism for the Select_Reactor by taking advantage of the priority method on ACE_Event_Handler.
Definition at line 37 of file Priority_Reactor.h.
      
  | 
  
| 
 There is a queue per-priority, which simply holds the Event_Handlers until we know who goes first. Definition at line 84 of file Priority_Reactor.h. Referenced by init_bucket().  | 
  
      
  | 
  ||||||||||||
| 
 Initialize with the default size. 
 Definition at line 43 of file Priority_Reactor.cpp. References ACE_Select_Reactor, ACE_Timer_Queue, ACE_TRACE, and init_bucket(). 
 00045 : ACE_Select_Reactor(sh, tq), 00046 bucket_ (0), 00047 tuple_allocator_ (0) 00048 { 00049 ACE_TRACE ("ACE_Priority_Reactor::ACE_Priority_Reactor"); 00050 this->init_bucket (); 00051 }  | 
  
      
  | 
  ||||||||||||||||||||
| 
 Initialize with size . 
 Definition at line 53 of file Priority_Reactor.cpp. References ACE_Select_Reactor, ACE_Timer_Queue, ACE_TRACE, and init_bucket(). 
 00057 : ACE_Select_Reactor (size, rs, sh, tq), 00058 bucket_ (0), 00059 tuple_allocator_ (0) 00060 { 00061 ACE_TRACE ("ACE_Priority_Reactor::ACE_Priority_Reactor"); 00062 this->init_bucket (); 00063 }  | 
  
      
  | 
  
| 
 Close down the select_reactor and release all of its resources. 
 Definition at line 65 of file Priority_Reactor.cpp. References ACE_TRACE, bucket_, npriorities, and tuple_allocator_. 
 00066 {
00067   ACE_TRACE ("ACE_Priority_Reactor::~ACE_Priority_Reactor");
00068 
00069   for (int i = 0; i < npriorities; ++i)
00070     delete this->bucket_[i];
00071 
00072   delete[] this->bucket_;
00073   delete tuple_allocator_;
00074 }
 | 
  
      
  | 
  
| 
 Deny access since member-wise won't work... 
  | 
  
      
  | 
  ||||||||||||||||
| 
 Build the bucket from the given dispatch_mask. 
 Definition at line 77 of file Priority_Reactor.cpp. References bucket_, ACE_Unbounded_Queue< T >::enqueue_tail(), ACE_Event_Tuple::event_handler_, and ACE_Event_Handler::priority(). Referenced by dispatch_io_set(). 
 00080 {
00081   ACE_Handle_Set_Iterator handle_iter (dispatch_mask);
00082 
00083   for (ACE_HANDLE handle;
00084        (handle = handle_iter ()) != ACE_INVALID_HANDLE;
00085        )
00086     {
00087       ACE_Event_Tuple et (this->handler_rep_.find (handle),
00088                           handle);
00089       int prio = et.event_handler_->priority ();
00090 
00091       // If the priority is out of range assign the minimum priority.
00092       if (prio < ACE_Event_Handler::LO_PRIORITY
00093           || prio > ACE_Event_Handler::HI_PRIORITY)
00094         prio = ACE_Event_Handler::LO_PRIORITY;
00095 
00096       bucket_[prio]->enqueue_tail (et);
00097 
00098       // Update the priority ranges....
00099       if (min_priority > prio)
00100         min_priority = prio;
00101       if (max_priority < prio)
00102         max_priority = prio;
00103     }
00104 
00105 }
 | 
  
      
  | 
  ||||||||||||||||||||||||||||
| 
 We simply override this function to implement the priority dispatching. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >. Definition at line 108 of file Priority_Reactor.cpp. References ACE_EH_PTMF, ACE_TRACE, bucket_, build_bucket(), ACE_Select_Reactor_Impl::clear_dispatch_mask(), ACE_Unbounded_Queue< T >::dequeue_head(), ACE_Event_Tuple::event_handler_, ACE_Event_Tuple::handle_, ACE_Unbounded_Queue< T >::is_empty(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::notify_handle(), and ACE_Unbounded_Queue< T >::reset(). 
 00114 {
00115   ACE_TRACE ("ACE_Priority_Reactor::dispatch_io_set");
00116 
00117   if (number_of_active_handles == 0)
00118     return 0;
00119 
00120   // The range for which there exists any Event_Tuple is computed on
00121   // the ordering loop, minimizing iterations on the dispatching loop.
00122   int min_priority =
00123     ACE_Event_Handler::HI_PRIORITY;
00124   int max_priority =
00125     ACE_Event_Handler::LO_PRIORITY;
00126 
00127   (void) this->build_bucket (dispatch_mask,
00128                              min_priority,
00129                              max_priority);
00130 
00131   for (int i = max_priority; i >= min_priority; --i)
00132     {
00133       while (!bucket_[i]->is_empty ()
00134              && number_dispatched < number_of_active_handles)
00135         {
00136 
00137           ACE_Event_Tuple et;
00138 
00139           bucket_[i]->dequeue_head (et);
00140 
00141           this->notify_handle (et.handle_,
00142                                mask,
00143                                ready_mask,
00144                                et.event_handler_,
00145                                callback);
00146           number_dispatched++;
00147 
00148           // clear the bit from that dispatch mask,
00149           // so when we need to restart the iteration (rebuilding the iterator...)
00150           // we will not dispatch the already dipatched handlers
00151           this->clear_dispatch_mask (et.handle_,
00152                                      mask);
00153 
00154           if (this->state_changed_)
00155             {
00156               this->state_changed_ = false; // so it will not rebuild it ...
00157             }
00158         }
00159 
00160       // Even if we are aborting the loop due to this->state_changed
00161       // or another error we still want to cleanup the buckets.
00162       bucket_[i]->reset ();
00163     }
00164 
00165   return 0;
00166 }
 | 
  
      
  | 
  
| 
 Dump the state of an object. 
 Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >. Definition at line 169 of file Priority_Reactor.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump(), and LM_DEBUG. 
 00170 {
00171 #if defined (ACE_HAS_DUMP)
00172   ACE_TRACE ("ACE_Priority_Reactor::dump");
00173 
00174   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00175 
00176   ACE_Select_Reactor::dump ();
00177 
00178   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00179 #endif /* ACE_HAS_DUMP */
00180 }
 | 
  
      
  | 
  
| 
 A small helper to initialize the bucket. 
 Definition at line 25 of file Priority_Reactor.cpp. References ACE_NEW, npriorities, QUEUE, and TUPLE_ALLOCATOR. Referenced by ACE_Priority_Reactor(). 
 00026 {
00027   // Allocate enough space for all the handles.
00028   // TODO: This can be wrong, maybe we should use other kind of
00029   // allocator here?
00030   ACE_NEW (this->tuple_allocator_,
00031            TUPLE_ALLOCATOR (ACE_Select_Reactor::DEFAULT_SIZE));
00032 
00033   // The event handlers are assigned to a new As the Event
00034   ACE_NEW (this->bucket_,
00035            QUEUE *[npriorities]);
00036 
00037   // This loops "ensures" exception safety.
00038   for (int i = 0; i < npriorities; ++i)
00039     ACE_NEW (this->bucket_[i],
00040              QUEUE (this->tuple_allocator_));
00041 }
 | 
  
      
  | 
  
| 
 
  | 
  
      
  | 
  
| 
 Declare the dynamic allocation hooks. 
 Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >. Definition at line 59 of file Priority_Reactor.h.  | 
  
      
  | 
  
| 
 
 Definition at line 85 of file Priority_Reactor.h. Referenced by build_bucket(), dispatch_io_set(), and ~ACE_Priority_Reactor().  | 
  
      
  | 
  
| 
 The queues themselves use this allocator to minimize dynamic memory usage. Definition at line 89 of file Priority_Reactor.h. Referenced by ~ACE_Priority_Reactor().  | 
  
 
1.3.6