00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ACE_TIMER_HASH_T_H
00014 #define ACE_TIMER_HASH_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 #include "ace/Free_List.h"
00024
00025 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027
00028 template <class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
00029 class ACE_Timer_Hash_T;
00030 template <typename TYPE>
00031 class Hash_Token;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00042 class ACE_Timer_Hash_Upcall
00043 {
00044 public:
00045 typedef ACE_Timer_Queue_T<ACE_Event_Handler *,
00046 ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>,
00047 ACE_Null_Mutex>
00048 TIMER_QUEUE;
00049
00050
00051
00052 ACE_Timer_Hash_Upcall (void);
00053
00054
00055 ACE_Timer_Hash_Upcall (ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> *timer_hash);
00056
00057
00058 int registration (TIMER_QUEUE &timer_queue,
00059 ACE_Event_Handler *handler,
00060 const void *arg);
00061
00062
00063 int preinvoke (TIMER_QUEUE &timer_queue,
00064 ACE_Event_Handler *handler,
00065 const void *arg,
00066 int recurring_timer,
00067 const ACE_Time_Value &cur_time,
00068 const void *&upcall_act);
00069
00070
00071 int timeout (TIMER_QUEUE &timer_queue,
00072 ACE_Event_Handler *handler,
00073 const void *arg,
00074 int recurring_timer,
00075 const ACE_Time_Value &cur_time);
00076
00077
00078 int postinvoke (TIMER_QUEUE &timer_queue,
00079 ACE_Event_Handler *handler,
00080 const void *arg,
00081 int recurring_timer,
00082 const ACE_Time_Value &cur_time,
00083 const void *upcall_act);
00084
00085
00086 int cancel_type (TIMER_QUEUE &timer_queue,
00087 ACE_Event_Handler *handler,
00088 int dont_call,
00089 int &requires_reference_counting);
00090
00091
00092 int cancel_timer (TIMER_QUEUE &timer_queue,
00093 ACE_Event_Handler *handler,
00094 int dont_call,
00095 int requires_reference_counting);
00096
00097
00098
00099 int deletion (TIMER_QUEUE &timer_queue,
00100 ACE_Event_Handler *handler,
00101 const void *arg);
00102
00103 private:
00104
00105 ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> *timer_hash_;
00106
00107
00108 ACE_UNIMPLEMENTED_FUNC (ACE_Timer_Hash_Upcall (const ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK> &))
00109 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK> &))
00110 };
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 template <class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
00122 class ACE_Timer_Hash_Iterator_T : public ACE_Timer_Queue_Iterator_T <TYPE, FUNCTOR, ACE_LOCK>
00123 {
00124 public:
00125
00126 ACE_Timer_Hash_Iterator_T (ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> &);
00127
00128
00129 virtual void first (void);
00130
00131
00132 virtual void next (void);
00133
00134
00135 virtual bool isdone (void) const;
00136
00137
00138 virtual ACE_Timer_Node_T<TYPE> *item (void);
00139
00140 protected:
00141
00142 ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> &timer_hash_;
00143
00144
00145 size_t position_;
00146
00147
00148 ACE_Timer_Queue_Iterator_T<TYPE, ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>, ACE_Null_Mutex> *iter_;
00149 };
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 template <class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
00162 class ACE_Timer_Hash_T : public ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>
00163 {
00164 public:
00165
00166 typedef ACE_Timer_Hash_Iterator_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>
00167 HASH_ITERATOR;
00168
00169
00170 friend class ACE_Timer_Hash_Iterator_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>;
00171
00172
00173 typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> INHERITED;
00174
00175
00176
00177
00178
00179
00180
00181
00182 ACE_Timer_Hash_T (size_t table_size,
00183 FUNCTOR *upcall_functor = 0,
00184 ACE_Free_List<ACE_Timer_Node_T <TYPE> > *freelist = 0);
00185
00186
00187
00188
00189
00190
00191
00192
00193 ACE_Timer_Hash_T (FUNCTOR *upcall_functor = 0, ACE_Free_List<ACE_Timer_Node_T <TYPE> > *freelist = 0);
00194
00195
00196 virtual ~ACE_Timer_Hash_T (void);
00197
00198
00199 virtual bool is_empty (void) const;
00200
00201
00202
00203 virtual const ACE_Time_Value &earliest_time (void) const;
00204
00205
00206
00207
00208
00209
00210
00211
00212 virtual int reset_interval (long timer_id,
00213 const ACE_Time_Value &interval);
00214
00215
00216
00217
00218
00219
00220
00221
00222 virtual int cancel (const TYPE &type,
00223 int dont_call_handle_close = 1);
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 virtual int cancel (long timer_id,
00237 const void **act = 0,
00238 int dont_call_handle_close = 1);
00239
00240
00241
00242
00243
00244
00245 virtual int expire (void);
00246
00247
00248
00249
00250
00251
00252 virtual int expire (const ACE_Time_Value ¤t_time);
00253
00254
00255 virtual ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, ACE_LOCK> &iter (void);
00256
00257
00258 virtual ACE_Timer_Node_T<TYPE> *remove_first (void);
00259
00260
00261 virtual void dump (void) const;
00262
00263
00264 virtual ACE_Timer_Node_T<TYPE> *get_first (void);
00265
00266 protected:
00267
00268 virtual void free_node (ACE_Timer_Node_T<TYPE> *);
00269
00270 private:
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 virtual long schedule_i (const TYPE &type,
00284 const void *act,
00285 const ACE_Time_Value &future_time,
00286 const ACE_Time_Value &interval);
00287
00288
00289 virtual int dispatch_info_i (const ACE_Time_Value ¤t_time,
00290 ACE_Timer_Node_Dispatch_Info_T<TYPE> &info);
00291
00292
00293 virtual void reschedule (ACE_Timer_Node_T<TYPE> *);
00294
00295
00296 void find_new_earliest (void);
00297
00298
00299 size_t size_;
00300
00301
00302 BUCKET **table_;
00303
00304
00305 size_t table_size_;
00306
00307
00308 ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK> table_functor_;
00309
00310
00311 size_t earliest_position_;
00312
00313
00314 HASH_ITERATOR *iterator_;
00315
00316 #if defined (ACE_WIN64)
00317
00318
00319 ptrdiff_t pointer_base_;
00320 #endif
00321
00322
00323
00324 ACE_Locked_Free_List<Hash_Token<TYPE>, ACE_Null_Mutex> token_list_;
00325
00326
00327 ACE_UNIMPLEMENTED_FUNC (ACE_Timer_Hash_T (const ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> &))
00328 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> &))
00329 };
00330
00331 ACE_END_VERSIONED_NAMESPACE_DECL
00332
00333 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00334 #include "ace/Timer_Hash_T.cpp"
00335 #endif
00336
00337 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00338 #pragma implementation ("Timer_Hash_T.cpp")
00339 #endif
00340
00341 #include "ace/post.h"
00342 #endif