Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Timer_Queue_T.h
blob060285cdf19b84999581df5fd377df92cecc928e
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Timer_Queue_T.h
7 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Irfan Pyarali <irfan@cs.wustl.edu> and
9 * @author Darrell Brunsch <brunsch@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_TIMER_QUEUE_T_H
14 #define ACE_TIMER_QUEUE_T_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Free_List.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Time_Value.h"
24 #include "ace/Abstract_Timer_Queue.h"
25 #include "ace/Timer_Queue_Iterator.h"
26 #include "ace/Time_Policy.h"
27 #include "ace/Copy_Disabled.h"
29 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
31 /**
32 * @class ACE_Timer_Queue_Upcall_Base
34 * Common base class for all timer queues with the same time source
35 * policy. This is really motivated by a single use-case in the code,
36 * namely the ACE_Proactor needs to set a backpointer in the upcall
37 * functor.
39 template<typename TYPE, typename FUNCTOR>
40 class ACE_Timer_Queue_Upcall_Base
41 : public ACE_Abstract_Timer_Queue<TYPE>
42 , private ACE_Copy_Disabled
44 public:
45 // Constructor
46 explicit ACE_Timer_Queue_Upcall_Base(FUNCTOR * upcall_functor = nullptr);
48 /// Destructor
49 virtual ~ACE_Timer_Queue_Upcall_Base ();
51 /// Accessor to the upcall functor
52 FUNCTOR & upcall_functor ();
54 protected:
55 /// Upcall functor
56 FUNCTOR *upcall_functor_;
58 /// To delete or not to delete is the question?
59 bool const delete_upcall_functor_;
62 /**
63 * @class ACE_Timer_Queue_T
65 * @brief Provides an interface to timers.
67 * This is an abstract base class that provides hook for
68 * implementing specialized policies such as ACE_Timer_List
69 * and ACE_Timer_Heap.
71 template <class TYPE, class FUNCTOR, class ACE_LOCK, typename TIME_POLICY = ACE_Default_Time_Policy>
72 class ACE_Timer_Queue_T
73 : public ACE_Timer_Queue_Upcall_Base<TYPE,FUNCTOR>
75 public:
76 /// Type of time policy
77 typedef TIME_POLICY time_policy_t;
79 /**
80 * Default constructor. @a upcall_functor is the instance of the
81 * FUNCTOR to be used by the queue. If @a upcall_functor is 0, Timer
82 * Queue will create a default FUNCTOR. @a freelist the freelist of
83 * timer nodes. If 0, then a default freelist will be created.
85 ACE_Timer_Queue_T (FUNCTOR *upcall_functor = 0,
86 ACE_Free_List<ACE_Timer_Node_T <TYPE> > *freelist = 0,
87 TIME_POLICY const & time_policy = TIME_POLICY());
89 /// Destructor - make virtual for proper destruction of inherited
90 /// classes.
91 virtual ~ACE_Timer_Queue_T ();
93 /**
94 * Implement ACE_Abstract_Timer_Queue<TYPE>::schedule () with the right
95 * locking strategy.
97 virtual long schedule (const TYPE &type,
98 const void *act,
99 const ACE_Time_Value &future_time,
100 const ACE_Time_Value &interval = ACE_Time_Value::zero);
102 //@{
104 * Implement ACE_Abstract_Timer_Queue<TYPE>::expire () with the right
105 * locking strategy.
107 virtual int expire (const ACE_Time_Value &current_time);
108 virtual int expire ();
109 virtual int expire_single(ACE_Command_Base & pre_dispatch_command);
110 //@}
113 * Get the dispatch information for a timer whose value is <= @a current_time.
114 * This does not account for <timer_skew>. Returns 1 if
115 * there is a node whose value <= @a current_time else returns a 0.
118 virtual int dispatch_info (const ACE_Time_Value &current_time,
119 ACE_Timer_Node_Dispatch_Info_T<TYPE> &info);
120 //@{
122 * Implement the gettimeofday() virtual function
124 virtual ACE_Time_Value gettimeofday ();
125 //@}
128 * Allows applications to control how the timer queue gets the time
129 * of day.
130 * @deprecated Use TIME_POLICY support instead.
131 * This will only have effect when the TIME_POLICY used
132 * is ACE_FPointer_Time_Policy. Other standard ACE time
133 * policies will ignore this.
135 virtual void gettimeofday (ACE_Time_Value (*gettimeofday)());
137 /// Implement an inlined, non-abstract version of gettimeofday(),
138 /// through this member function the internals of the class can
139 /// make calls to ACE_OS::gettimeofday() with zero overhead.
140 ACE_Time_Value gettimeofday_static();
142 /// Allows applications to control how the timer queue gets the time
143 /// of day.
144 void set_time_policy(TIME_POLICY const & time_policy);
146 /// Determine the next event to timeout. Returns @a max if there are
147 /// no pending timers or if all pending timers are longer than max.
148 /// This method acquires a lock internally since it modifies internal state.
149 //@{
151 * Implement calculate_timeout() using the right locking policy
153 virtual ACE_Time_Value *calculate_timeout (ACE_Time_Value *max);
154 virtual ACE_Time_Value *calculate_timeout (ACE_Time_Value *max,
155 ACE_Time_Value *the_timeout);
156 virtual ACE_Time_Value current_time();
157 //@}
159 /// Set the timer skew for the Timer_Queue.
160 void timer_skew (const ACE_Time_Value &skew);
162 /// Get the timer skew for the Timer_Queue.
163 const ACE_Time_Value &timer_skew () const;
165 /// Synchronization variable used by the queue
166 ACE_LOCK &mutex ();
168 /// Dump the state of a object.
169 virtual void dump () const;
171 /// Method used to return a timer node to the queue's ownership
172 /// after it is returned by a method like <remove_first>.
173 virtual void return_node (ACE_Timer_Node_T<TYPE> *);
175 /// This method will call the preinvoke() on <functor>.
176 void preinvoke (ACE_Timer_Node_Dispatch_Info_T<TYPE> &info,
177 const ACE_Time_Value &cur_time,
178 const void *&upcall_act);
180 /// This method will call the timeout() on <functor>.
181 void upcall (ACE_Timer_Node_Dispatch_Info_T<TYPE> &info,
182 const ACE_Time_Value &cur_time);
184 /// This method will call the postinvoke() on <functor>.
185 void postinvoke (ACE_Timer_Node_Dispatch_Info_T<TYPE> &info,
186 const ACE_Time_Value &cur_time,
187 const void *upcall_act);
189 protected:
190 /// Schedule a timer.
191 virtual long schedule_i (const TYPE &type,
192 const void *act,
193 const ACE_Time_Value &future_time,
194 const ACE_Time_Value &interval) = 0;
196 /// Reschedule an "interval" ACE_Timer_Node.
197 virtual void reschedule (ACE_Timer_Node_T<TYPE> *) = 0;
199 /// Factory method that allocates a new node.
200 virtual ACE_Timer_Node_T<TYPE> *alloc_node ();
202 /// Factory method that frees a previously allocated node.
203 virtual void free_node (ACE_Timer_Node_T<TYPE> *);
205 /// Non-locking version of dispatch_info ()
206 virtual int dispatch_info_i (const ACE_Time_Value &current_time,
207 ACE_Timer_Node_Dispatch_Info_T<TYPE> &info);
209 /// Recompute when the next time is that this interval timer should fire.
210 void recompute_next_abs_interval_time (ACE_Timer_Node_T<TYPE>* expired,
211 const ACE_Time_Value &cur_time);
213 /// Synchronization variable for ACE_Timer_Queue.
214 /// @note The right name would be lock_, but HP/C++ will choke on that!
215 ACE_LOCK mutex_;
217 /// Class that implements a free list
218 ACE_Free_List<ACE_Timer_Node_T<TYPE> > *free_list_;
220 /// The policy to return the current time of day
221 TIME_POLICY time_policy_;
223 /// Flag to delete only if the class created the <free_list_>
224 bool const delete_free_list_;
226 private:
227 /// Returned by <calculate_timeout>.
228 ACE_Time_Value timeout_;
230 /// Adjusts for timer skew in various clocks.
231 ACE_Time_Value timer_skew_;
234 ACE_END_VERSIONED_NAMESPACE_DECL
236 #if defined (__ACE_INLINE__)
237 #include "ace/Timer_Queue_T.inl"
238 #endif /* __ACE_INLINE__ */
240 #include "ace/Timer_Queue_T.cpp"
242 #include /**/ "ace/post.h"
243 #endif /* ACE_TIMER_QUEUE_T_H */