#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 ACE_Priority_Reactor with the default size. | |
ACE_Priority_Reactor (size_t size, int restart=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0) | |
Initialize ACE_Priority_Reactor with size 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. | |
int | build_bucket (ACE_Handle_Set &dispatch_mask, int &min_priority, int &max_priority) |
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.
typedef ACE_Unbounded_Queue<ACE_Event_Tuple> ACE_Priority_Reactor::QUEUE [private] |
There is a queue per-priority, which simply holds the Event_Handlers until we know who goes first.
Definition at line 85 of file Priority_Reactor.h.
ACE_Priority_Reactor::ACE_Priority_Reactor | ( | ACE_Sig_Handler * | = 0 , |
|
ACE_Timer_Queue * | = 0 | |||
) |
Initialize ACE_Priority_Reactor with the default size.
Definition at line 43 of file Priority_Reactor.cpp.
References 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 }
ACE_Priority_Reactor::ACE_Priority_Reactor | ( | size_t | size, | |
int | restart = 0 , |
|||
ACE_Sig_Handler * | = 0 , |
|||
ACE_Timer_Queue * | = 0 | |||
) |
Initialize ACE_Priority_Reactor with size size.
Definition at line 53 of file Priority_Reactor.cpp.
References 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 }
ACE_Priority_Reactor::~ACE_Priority_Reactor | ( | void | ) | [virtual] |
Close down the select_reactor and release all of its resources.
Definition at line 65 of file Priority_Reactor.cpp.
References ACE_TRACE, 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 }
ACE_Priority_Reactor::ACE_Priority_Reactor | ( | const ACE_Priority_Reactor & | ) | [private] |
Deny access since member-wise won't work...
int ACE_Priority_Reactor::build_bucket | ( | ACE_Handle_Set & | dispatch_mask, | |
int & | min_priority, | |||
int & | max_priority | |||
) | [private] |
Build the bucket from the given dispatch_mask. Return -1 on failure, 0 otherwise.
Definition at line 77 of file Priority_Reactor.cpp.
References bucket_, ACE_Event_Tuple::event_handler_, ACE_Event_Handler::HI_PRIORITY, ACE_Event_Handler::LO_PRIORITY, and ACE_Event_Handler::priority().
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_Handler *event_handler = 00088 this->handler_rep_.find (handle); 00089 if (event_handler == 0) 00090 return -1; 00091 00092 ACE_Event_Tuple et (event_handler, 00093 handle); 00094 int prio = et.event_handler_->priority (); 00095 00096 // If the priority is out of range assign the minimum priority. 00097 if (prio < ACE_Event_Handler::LO_PRIORITY 00098 || prio > ACE_Event_Handler::HI_PRIORITY) 00099 prio = ACE_Event_Handler::LO_PRIORITY; 00100 00101 if (bucket_[prio]->enqueue_tail (et) == -1) 00102 return -1; 00103 00104 // Update the priority ranges.... 00105 if (min_priority > prio) 00106 min_priority = prio; 00107 if (max_priority < prio) 00108 max_priority = prio; 00109 } 00110 00111 return 0; 00112 }
int ACE_Priority_Reactor::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 | |||
) | [protected, virtual] |
We simply override this function to implement the priority dispatching.
Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.
Definition at line 115 of file Priority_Reactor.cpp.
References ACE_TRACE, bucket_, ACE_Select_Reactor_Impl::clear_dispatch_mask(), ACE_Unbounded_Queue< T >::dequeue_head(), ACE_Event_Handler::HI_PRIORITY, is_empty(), ACE_Event_Handler::LO_PRIORITY, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::notify_handle(), ACE_Unbounded_Queue< T >::reset(), and ACE_Select_Reactor_Impl::state_changed_.
00121 { 00122 ACE_TRACE ("ACE_Priority_Reactor::dispatch_io_set"); 00123 00124 if (number_of_active_handles == 0) 00125 return 0; 00126 00127 // The range for which there exists any Event_Tuple is computed on 00128 // the ordering loop, minimizing iterations on the dispatching loop. 00129 int min_priority = 00130 ACE_Event_Handler::HI_PRIORITY; 00131 int max_priority = 00132 ACE_Event_Handler::LO_PRIORITY; 00133 00134 if (this->build_bucket (dispatch_mask, 00135 min_priority, 00136 max_priority) == -1) 00137 return -1; 00138 00139 for (int i = max_priority; i >= min_priority; --i) 00140 { 00141 while (!bucket_[i]->is_empty () 00142 && number_dispatched < number_of_active_handles) 00143 { 00144 00145 ACE_Event_Tuple et; 00146 00147 bucket_[i]->dequeue_head (et); 00148 00149 this->notify_handle (et.handle_, 00150 mask, 00151 ready_mask, 00152 et.event_handler_, 00153 callback); 00154 number_dispatched++; 00155 00156 // clear the bit from that dispatch mask, 00157 // so when we need to restart the iteration (rebuilding the iterator...) 00158 // we will not dispatch the already dipatched handlers 00159 this->clear_dispatch_mask (et.handle_, 00160 mask); 00161 00162 if (this->state_changed_) 00163 this->state_changed_ = false; // so it will not rebuild it ... 00164 } 00165 00166 // Even if we are aborting the loop due to this->state_changed 00167 // or another error we still want to cleanup the buckets. 00168 bucket_[i]->reset (); 00169 } 00170 00171 return 0; 00172 }
void ACE_Priority_Reactor::dump | ( | void | ) | const [virtual] |
Dump the state of an object.
Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.
Definition at line 175 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.
00176 { 00177 #if defined (ACE_HAS_DUMP) 00178 ACE_TRACE ("ACE_Priority_Reactor::dump"); 00179 00180 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00181 00182 ACE_Select_Reactor::dump (); 00183 00184 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00185 #endif /* ACE_HAS_DUMP */ 00186 }
void ACE_Priority_Reactor::init_bucket | ( | void | ) | [private] |
A small helper to initialize the bucket.
Definition at line 25 of file Priority_Reactor.cpp.
References ACE_NEW, ACE_Select_Reactor_Impl::DEFAULT_SIZE, and npriorities.
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 }
ACE_Priority_Reactor& ACE_Priority_Reactor::operator= | ( | const ACE_Priority_Reactor & | ) | [private] |
Declare the dynamic allocation hooks.
Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.
Definition at line 59 of file Priority_Reactor.h.
QUEUE** ACE_Priority_Reactor::bucket_ [private] |
Definition at line 86 of file Priority_Reactor.h.
Referenced by build_bucket(), and dispatch_io_set().
The queues themselves use this allocator to minimize dynamic memory usage.
Definition at line 90 of file Priority_Reactor.h.
Referenced by ~ACE_Priority_Reactor().