00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ACE_TIMER_WHEEL_T_H
00014 #define ACE_TIMER_WHEEL_T_H
00015 #include "ace/pre.h"
00016
00017 #include "ace/Timer_Queue_T.h"
00018
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif
00022
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024
00025
00026 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00027 class ACE_Timer_Wheel_T;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00039 class ACE_Timer_Wheel_Iterator_T
00040 : public ACE_Timer_Queue_Iterator_T <TYPE, FUNCTOR, ACE_LOCK>
00041 {
00042 public:
00043 typedef ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> Wheel;
00044 typedef ACE_Timer_Node_T<TYPE> Node;
00045
00046
00047 ACE_Timer_Wheel_Iterator_T (Wheel &);
00048
00049
00050 ~ACE_Timer_Wheel_Iterator_T (void);
00051
00052
00053 virtual void first (void);
00054
00055
00056 virtual void next (void);
00057
00058
00059 virtual int isdone (void) const;
00060
00061
00062 virtual ACE_Timer_Node_T<TYPE>* item (void);
00063
00064 protected:
00065
00066 Wheel& timer_wheel_;
00067
00068
00069 u_int spoke_;
00070
00071
00072 ACE_Timer_Node_T<TYPE>* current_node_;
00073 private:
00074 void goto_next(u_int start_spoke);
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00092 class ACE_Timer_Wheel_T : public ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>
00093 {
00094 public:
00095
00096 typedef ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK> Iterator;
00097
00098 friend class ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>;
00099 typedef ACE_Timer_Node_T<TYPE> Node;
00100
00101 typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> Base;
00102 typedef ACE_Free_List<Node> FreeList;
00103
00104
00105 ACE_Timer_Wheel_T (FUNCTOR* upcall_functor = 0, FreeList* freelist = 0);
00106
00107
00108 ACE_Timer_Wheel_T (u_int spoke_count,
00109 u_int resolution,
00110 size_t prealloc = 0,
00111 FUNCTOR* upcall_functor = 0,
00112 FreeList* freelist = 0);
00113
00114
00115 virtual ~ACE_Timer_Wheel_T (void);
00116
00117
00118 virtual int is_empty (void) const;
00119
00120
00121
00122 virtual const ACE_Time_Value& earliest_time (void) const;
00123
00124
00125
00126 virtual int reset_interval (long timer_id,
00127 const ACE_Time_Value& interval);
00128
00129
00130
00131
00132 virtual int cancel (const TYPE& type,
00133 int dont_call_handle_close = 1);
00134
00135
00136
00137
00138 virtual int cancel (long timer_id,
00139 const void** act = 0,
00140 int dont_call_handle_close = 1);
00141
00142
00143
00144
00145 virtual int expire (void);
00146
00147
00148
00149
00150 int expire (const ACE_Time_Value&);
00151
00152
00153 virtual ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>& iter (void);
00154
00155
00156 virtual ACE_Timer_Node_T<TYPE>* remove_first (void);
00157
00158
00159 virtual void dump (void) const;
00160
00161
00162 virtual ACE_Timer_Node_T<TYPE>* get_first (void);
00163
00164 protected:
00165
00166
00167 virtual long schedule_i (const TYPE& type,
00168 const void* act,
00169 const ACE_Time_Value& future_time,
00170 const ACE_Time_Value& interval);
00171
00172 private:
00173
00174 ACE_Timer_Node_T<TYPE>* get_first_i (void) const;
00175 ACE_Timer_Node_T<TYPE>* remove_first_expired (const ACE_Time_Value& now);
00176 void open_i (size_t prealloc, u_int spokes, u_int res);
00177 virtual void reschedule (ACE_Timer_Node_T<TYPE> *);
00178 ACE_Timer_Node_T<TYPE>* find_spoke_node(u_int spoke, long timer_id) const;
00179 ACE_Timer_Node_T<TYPE>* find_node(long timer_id) const;
00180 u_int calculate_spoke(const ACE_Time_Value& expire) const;
00181 long generate_timer_id(u_int spoke);
00182 void schedule_i (ACE_Timer_Node_T<TYPE>* n, u_int spoke, const ACE_Time_Value& expire);
00183 void cancel_i (ACE_Timer_Node_T<TYPE>* n);
00184 void unlink (ACE_Timer_Node_T<TYPE>* n);
00185 void recalc_earliest(const ACE_Time_Value& last);
00186
00187 private:
00188 int power2bits (int n, int min_bits, int max_bits);
00189
00190
00191 ACE_Timer_Node_T<TYPE>** spokes_;
00192
00193 u_int spoke_count_;
00194
00195 int spoke_bits_;
00196
00197 u_int max_per_spoke_;
00198
00199 int res_bits_;
00200
00201 u_int earliest_spoke_;
00202
00203 Iterator* iterator_;
00204
00205 ACE_Time_Value wheel_time_;
00206
00207 u_int timer_count_;
00208
00209
00210
00211 ACE_UNIMPLEMENTED_FUNC (ACE_Timer_Wheel_T (const ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> &))
00212 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> &))
00213 };
00214
00215 ACE_END_VERSIONED_NAMESPACE_DECL
00216
00217 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00218 #if !defined (ACE_HAS_BROKEN_HPUX_TEMPLATES)
00219 #include "ace/Timer_Wheel_T.cpp"
00220 #endif
00221 #endif
00222
00223 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00224 #pragma implementation ("Timer_Wheel_T.cpp")
00225 #endif
00226
00227 #include "ace/post.h"
00228 #endif