ACE_Proactor_Timer_Handler Class Reference

A Handler for timer. It helps in the management of timers registered with the Proactor. More...

Inheritance diagram for ACE_Proactor_Timer_Handler:

Inheritance graph
[legend]
Collaboration diagram for ACE_Proactor_Timer_Handler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Proactor_Timer_Handler (ACE_Proactor &proactor)
 Constructor.

virtual ~ACE_Proactor_Timer_Handler (void)
 Destructor.

int destroy (void)

Protected Member Functions

virtual int svc (void)

Protected Attributes

ACE_Auto_Event timer_event_
 Event to wait on.

ACE_Proactorproactor_
 Proactor.

int shutting_down_
 Flag used to indicate when we are shutting down.


Friends

class ACE_Proactor

Detailed Description

A Handler for timer. It helps in the management of timers registered with the Proactor.

This object has a thread that will wait on the earliest time in a list of timers and an event. When a timer expires, the thread will post a completion event on the port and go back to waiting on the timer queue and event. If the event is signaled, the thread will refresh the time it is currently waiting on (in case the earliest time has changed).

Definition at line 63 of file Proactor.cpp.


Constructor & Destructor Documentation

ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler ACE_Proactor proactor  ) 
 

Constructor.

Definition at line 98 of file Proactor.cpp.

00099   : ACE_Task <ACE_NULL_SYNCH> (&proactor.thr_mgr_),
00100     proactor_ (proactor),
00101     shutting_down_ (0)
00102 {
00103 }

ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler void   )  [virtual]
 

Destructor.

Definition at line 105 of file Proactor.cpp.

References ACE_Event::signal(), ACE_Task_Base::thr_mgr(), timer_event_, and ACE_Thread_Manager::wait_grp().

00106 {
00107   // Mark for closing down.
00108   this->shutting_down_ = 1;
00109 
00110   // Signal timer event.
00111   this->timer_event_.signal ();
00112 
00113   // Wait for the Timer Handler thread to exit.
00114   this->thr_mgr ()->wait_grp (this->grp_id ());
00115 }


Member Function Documentation

int ACE_Proactor_Timer_Handler::destroy void   ) 
 

Proactor calls this to shut down the timer handler gracefully. Just calling the destructor alone doesnt do what does. make sure the thread exits properly.

int ACE_Proactor_Timer_Handler::svc void   )  [protected, virtual]
 

Run by a daemon thread to handle deferred processing. In other words, this method will do the waiting on the earliest timer and event.

Reimplemented from ACE_Task_Base.

Definition at line 118 of file Proactor.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ETIME, LM_ERROR, timer_event_, ACE_Proactor::timer_queue(), and ACE_Event::wait().

00119 {
00120   ACE_Time_Value absolute_time;
00121   ACE_Time_Value relative_time;
00122   int result = 0;
00123 
00124   while (this->shutting_down_ == 0)
00125     {
00126       // Check whether the timer queue has any items in it.
00127       if (this->proactor_.timer_queue ()->is_empty () == 0)
00128         {
00129           // Get the earliest absolute time.
00130           absolute_time = this->proactor_.timer_queue ()->earliest_time ();
00131 
00132           // Get current time from timer queue since we don't know
00133           // which <gettimeofday> was used.
00134           ACE_Time_Value cur_time = this->proactor_.timer_queue ()->gettimeofday ();
00135 
00136           // Compare absolute time with curent time received from the
00137           // timer queue.
00138           if (absolute_time > cur_time)
00139             relative_time = absolute_time - cur_time;
00140           else
00141             relative_time = ACE_Time_Value::zero;
00142 
00143           // Block for relative time.
00144           result = this->timer_event_.wait (&relative_time, 0);
00145         }
00146       else
00147         // The timer queue has no entries, so wait indefinitely.
00148         result = this->timer_event_.wait ();
00149 
00150       // Check for timer expiries.
00151       if (result == -1)
00152         {
00153           switch (errno)
00154             {
00155             case ETIME:
00156               // timeout: expire timers
00157               this->proactor_.timer_queue ()->expire ();
00158               break;
00159             default:
00160               // Error.
00161               ACE_ERROR_RETURN ((LM_ERROR,
00162                                  ACE_LIB_TEXT ("%N:%l:(%P | %t):%p\n"),
00163                                  ACE_LIB_TEXT ("ACE_Proactor_Timer_Handler::svc:wait failed")),
00164                                 -1);
00165             }
00166         }
00167     }
00168   return 0;
00169 }


Friends And Related Function Documentation

friend class ACE_Proactor [friend]
 

Proactor has special privileges Access needed to: timer_event_

Definition at line 68 of file Proactor.cpp.


Member Data Documentation

ACE_Proactor& ACE_Proactor_Timer_Handler::proactor_ [protected]
 

Proactor.

Definition at line 92 of file Proactor.cpp.

int ACE_Proactor_Timer_Handler::shutting_down_ [protected]
 

Flag used to indicate when we are shutting down.

Definition at line 95 of file Proactor.cpp.

ACE_Auto_Event ACE_Proactor_Timer_Handler::timer_event_ [protected]
 

Event to wait on.

Definition at line 89 of file Proactor.cpp.

Referenced by ACE_Proactor::schedule_timer(), svc(), and ~ACE_Proactor_Timer_Handler().


The documentation for this class was generated from the following file:
Generated on Thu Nov 9 11:27:18 2006 for ACE by doxygen 1.3.6