00001
00002
00003 #ifndef ACE_TIMER_WHEEL_T_C
00004 #define ACE_TIMER_WHEEL_T_C
00005
00006 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00007 # pragma once
00008 #endif
00009
00010 #include "ace/Timer_Wheel_T.h"
00011 #include "ace/Log_Msg.h"
00012
00013 ACE_RCSID(ace, Timer_Wheel_T, "$Id: Timer_Wheel_T.cpp,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $")
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00044 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::ACE_Timer_Wheel_T
00045 (FUNCTOR* upcall_functor
00046 , FreeList* freelist
00047 )
00048 : Base (upcall_functor, freelist)
00049 , spokes_(0)
00050 , spoke_count_(0)
00051 , spoke_bits_(0)
00052 , res_bits_ (0)
00053 , earliest_spoke_ (0)
00054 , iterator_(0)
00055 , timer_count_(0)
00056 {
00057 ACE_TRACE ("ACE_Timer_Wheel_T::ACE_Timer_Wheel_T");
00058 this->open_i (0,
00059 ACE_DEFAULT_TIMER_WHEEL_SIZE,
00060 ACE_DEFAULT_TIMER_WHEEL_RESOLUTION);
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00074 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::ACE_Timer_Wheel_T
00075 (u_int spoke_count,
00076 u_int resolution,
00077 size_t prealloc,
00078 FUNCTOR* upcall_functor,
00079 FreeList* freelist)
00080 : Base (upcall_functor, freelist)
00081 , spokes_ (0)
00082 , spoke_count_ (0)
00083 , spoke_bits_ (0)
00084 , res_bits_ (0)
00085 , earliest_spoke_ (0)
00086 , iterator_ (0)
00087 , timer_count_ (0)
00088 {
00089 ACE_TRACE ("ACE_Timer_Wheel_T::ACE_Timer_Wheel_T");
00090 this->open_i (prealloc, spoke_count, resolution);
00091 }
00092
00093 namespace {
00094 int power2bits(int n, int min_bits, int max_bits) {
00095 int max = (1 << max_bits) - 1;
00096 if (n > max) {
00097 return max_bits;
00098 }
00099
00100 int i = 0;
00101 int tmp = n;
00102 do {
00103 tmp >>= 1;
00104 ++i;
00105 } while (tmp != 0);
00106
00107 if (i <= min_bits) {
00108 return min_bits;
00109 }
00110
00111 int a = (1 << i) - n;
00112 int b = (1 << (i - 1)) - n;
00113 if (b < 0)
00114 b = -b;
00115 if (b < a)
00116 return i - 1;
00117 return i;
00118 }
00119 }
00120
00121
00122
00123
00124
00125 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00126 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::open_i
00127 (size_t prealloc, u_int spokes, u_int res)
00128 {
00129 ACE_TRACE ("ACE_Timer_Wheel_T::open_i");
00130
00131 this->gettimeofday (ACE_OS::gettimeofday);
00132
00133
00134
00135 const int MIN_SPOKE_BITS = 3;
00136 const int MAX_SPOKE_BITS = 12;
00137 const int MAX_RES_BITS = 20;
00138
00139 this->spoke_bits_ = power2bits (spokes, MIN_SPOKE_BITS, MAX_SPOKE_BITS);
00140 this->res_bits_ = power2bits (res, 1, MAX_RES_BITS);
00141
00142 this->spoke_count_ = 1 << this->spoke_bits_;
00143
00144 this->free_list_->resize (prealloc + this->spoke_count_);
00145
00146 this->wheel_time_.msec (1 << (this->res_bits_ + this->spoke_bits_));
00147
00148 ACE_NEW (this->spokes_, ACE_Timer_Node_T<TYPE>* [this->spoke_count_]);
00149
00150
00151 for (u_int i = 0; i < this->spoke_count_; ++i)
00152 {
00153 ACE_Timer_Node_T<TYPE>* root = this->alloc_node ();
00154 root->set (0, 0, ACE_Time_Value::zero, ACE_Time_Value::zero, root, root, 0);
00155 this->spokes_[i] = root;
00156 }
00157
00158 ACE_NEW (iterator_, Iterator (*this));
00159 }
00160
00161
00162 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00163 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::~ACE_Timer_Wheel_T (void)
00164 {
00165 ACE_TRACE ("ACE_Timer_Wheel_T::~ACE_Timer_Wheel_T");
00166
00167 delete iterator_;
00168
00169 for (u_int i = 0; i < this->spoke_count_; ++i)
00170 {
00171
00172 ACE_Timer_Node_T<TYPE>* root = this->spokes_[i];
00173 for (ACE_Timer_Node_T<TYPE>* n = root->get_next (); n != root;)
00174 {
00175 ACE_Timer_Node_T<TYPE>* next = n->get_next ();
00176 this->upcall_functor ().deletion (*this, n->get_type (), n->get_act ());
00177 this->free_node (n);
00178 n = next;
00179 }
00180 delete root;
00181 }
00182 delete[] this->spokes_;
00183 }
00184
00185
00186 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00187 ACE_Timer_Node_T<TYPE>*
00188 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::find_spoke_node
00189 (u_int spoke, long timer_id) const
00190 {
00191 ACE_Timer_Node_T<TYPE>* root = this->spokes_[spoke];
00192 for (ACE_Timer_Node_T<TYPE>* n = root->get_next ();
00193 n != root;
00194 n = n->get_next ())
00195 {
00196 if (n->get_timer_id () == timer_id)
00197 return n;
00198 }
00199 return 0;
00200 }
00201
00202
00203
00204 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00205 ACE_Timer_Node_T<TYPE>*
00206 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::find_node (long timer_id) const
00207 {
00208 if (timer_id == -1)
00209 return 0;
00210
00211
00212 u_int spoke_mask = this->spoke_count_ - 1;
00213 u_int start = timer_id & spoke_mask;
00214 ACE_Timer_Node_T<TYPE>* n = this->find_spoke_node (start, timer_id);
00215 if (n != 0)
00216 return n;
00217
00218
00219
00220
00221 for (u_int i = 0; i < this->spoke_count_; ++i)
00222 {
00223 if (i != start)
00224 {
00225 n = this->find_spoke_node (i, timer_id);
00226 if (n != 0)
00227 return n;
00228 }
00229 }
00230
00231
00232 return 0;
00233 }
00234
00235
00236
00237
00238
00239
00240 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00241 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::is_empty (void) const
00242 {
00243 ACE_TRACE ("ACE_Timer_Wheel_T::is_empty");
00244 return timer_count_ == 0;
00245 }
00246
00247
00248
00249
00250
00251 template <class TYPE, class FUNCTOR, class ACE_LOCK> const ACE_Time_Value &
00252 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::earliest_time (void) const
00253 {
00254 ACE_TRACE ("ACE_Timer_Wheel_T::earliest_time");
00255 ACE_Timer_Node_T<TYPE>* n = this->get_first_i ();
00256 if (n != 0)
00257 return n->get_timer_value ();
00258 return ACE_Time_Value::zero;
00259 }
00260
00261
00262
00263
00264 template <class TYPE, class FUNCTOR, class ACE_LOCK> u_int
00265 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::calculate_spoke
00266 (const ACE_Time_Value& t) const
00267 {
00268 return ACE_static_cast(u_int, (t.msec () >> this->res_bits_) & (this->spoke_count_ - 1));
00269 }
00270
00271
00272
00273
00274
00275
00276 template <class TYPE, class FUNCTOR, class ACE_LOCK> long
00277 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::generate_timer_id (u_int spoke)
00278 {
00279
00280 int cnt_bits = sizeof (long) * 8 - this->spoke_bits_;
00281 long max_cnt = ((long)1 << cnt_bits) - 1;
00282 if (spoke == this->spoke_count_)
00283 --max_cnt;
00284
00285 ACE_Timer_Node_T<TYPE>* root = this->spokes_[spoke];
00286
00287 if (root == root->get_next ())
00288 root->set_act(0);
00289
00290
00291
00292
00293 #if defined (ACE_WIN64)
00294
00295
00296 # pragma warning(push)
00297 # pragma warning(disable : 4311)
00298 #endif
00299 long next_cnt = ACE_reinterpret_cast (long, root->get_act ());
00300 #if defined (ACE_WIN64)
00301 # pragma warning(pop)
00302 #endif
00303
00304
00305 long cnt = root->get_timer_id ();
00306
00307 if (cnt >= max_cnt && root == root->get_next ())
00308 {
00309
00310
00311
00312
00313 root->set_timer_id (1);
00314 return spoke;
00315 }
00316 else if (cnt >= max_cnt)
00317 {
00318 cnt = 0;
00319 }
00320 else if (next_cnt == 0 || cnt < next_cnt)
00321 {
00322 root->set_timer_id (cnt + 1);
00323 return (cnt << this->spoke_bits_) | spoke;
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333 for (; cnt < max_cnt - 1; ++cnt)
00334 {
00335 long id = (cnt << this->spoke_bits_) | spoke;
00336 ACE_Timer_Node_T<TYPE>* n = this->find_spoke_node (spoke, id);
00337 if (n == 0)
00338 {
00339 root->set_timer_id (cnt + 1);
00340
00341 next_cnt = 0;
00342 for (; n != root; n = n->get_next ())
00343 {
00344 long tmp = n->get_timer_id () >> this->spoke_bits_;
00345 if (tmp > cnt && (tmp < next_cnt || next_cnt == 0))
00346 next_cnt = tmp;
00347 }
00348 #if defined (ACE_WIN64)
00349
00350
00351 # pragma warning(push)
00352 # pragma warning(disable : 4312)
00353 #endif
00354 root->set_act (ACE_reinterpret_cast (void*, next_cnt));
00355 #if defined (ACE_WIN64)
00356 # pragma warning(pop)
00357 #endif
00358 return id;
00359 }
00360 }
00361
00362 return -1;
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 template <class TYPE, class FUNCTOR, class ACE_LOCK> long
00379 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::schedule (
00380 const TYPE& type,
00381 const void* act,
00382 const ACE_Time_Value& future_time,
00383 const ACE_Time_Value& interval
00384 )
00385 {
00386 ACE_TRACE ("ACE_Timer_Wheel_T::schedule");
00387 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00388
00389 ACE_Timer_Node_T<TYPE>* n = this->alloc_node ();
00390
00391 if (n != 0)
00392 {
00393 u_int spoke = calculate_spoke (future_time);
00394 long id = generate_timer_id (spoke);
00395
00396
00397
00398 if (id != -1)
00399 {
00400 n->set (type, act, future_time, interval, 0, 0, id);
00401 this->schedule_i (n, spoke, future_time);
00402 }
00403 return id;
00404 }
00405
00406
00407 errno = ENOMEM;
00408 return -1;
00409 }
00410
00411
00412
00413
00414
00415
00416
00417 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00418 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::reschedule (ACE_Timer_Node_T<TYPE>* n)
00419 {
00420 ACE_TRACE ("ACE_Timer_Wheel_T::reschedule");
00421 const ACE_Time_Value& expire = n->get_timer_value ();
00422 u_int spoke = calculate_spoke (expire);
00423 this->schedule_i (n, spoke, expire);
00424 }
00425
00426
00427 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00428 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::schedule_i
00429 (ACE_Timer_Node_T<TYPE>* n,
00430 u_int spoke,
00431 const ACE_Time_Value& expire)
00432 {
00433
00434 if (this->is_empty() || expire < this->earliest_time ())
00435 this->earliest_spoke_ = spoke;
00436
00437 ACE_Timer_Node_T<TYPE>* root = this->spokes_[spoke];
00438 ACE_Timer_Node_T<TYPE>* last = root->get_prev ();
00439
00440 ++timer_count_;
00441
00442
00443 if (last == root) {
00444 n->set_prev (root);
00445 n->set_next (root);
00446 root->set_prev (n);
00447 root->set_next (n);
00448 return;
00449 }
00450
00451
00452
00453
00454 ACE_Timer_Node_T<TYPE>* p = root->get_prev ();
00455 while (p != root && p->get_timer_value () > expire)
00456 p = p->get_prev ();
00457
00458
00459 n->set_prev (p);
00460 n->set_next (p->get_next ());
00461 p->get_next ()->set_prev (n);
00462 p->set_next (n);
00463 }
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00476 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::reset_interval (long timer_id,
00477 const ACE_Time_Value &interval
00478 )
00479 {
00480 ACE_TRACE ("ACE_Timer_Wheel_T::reset_interval");
00481 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00482 ACE_Timer_Node_T<TYPE>* n = this->find_node (timer_id);
00483 if (n != 0)
00484 {
00485
00486 n->set_interval (interval);
00487 return 0;
00488 }
00489 return -1;
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00506 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::cancel (const TYPE& type, int skip_close)
00507 {
00508 ACE_TRACE ("ACE_Timer_Wheel_T::cancel");
00509 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00510
00511 int num_canceled = 0;
00512
00513 if (!this->is_empty ())
00514 {
00515 ACE_Timer_Node_T<TYPE>* first = this->get_first ();
00516 ACE_Time_Value last = first->get_timer_value ();
00517 int recalc = 0;
00518
00519 for (u_int i = 0; i < this->spoke_count_; ++i)
00520 {
00521 ACE_Timer_Node_T<TYPE>* root = this->spokes_[i];
00522 for (ACE_Timer_Node_T<TYPE>* n = root->get_next (); n != root; )
00523 {
00524 if (n->get_type () == type)
00525 {
00526 ++num_canceled;
00527 if (n == first)
00528 recalc = 1;
00529
00530 ACE_Timer_Node_T<TYPE>* tmp = n;
00531 n = n->get_next ();
00532 int always_skip_close = 1;
00533 this->cancel_i (tmp, always_skip_close);
00534 }
00535 else
00536 {
00537 n = n->get_next ();
00538 }
00539 }
00540 }
00541
00542 if (recalc)
00543 this->recalc_earliest (last);
00544 }
00545
00546 if (!skip_close)
00547 this->upcall_functor().cancellation (*this, type);
00548
00549 return num_canceled;
00550 }
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00571 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::cancel (long timer_id,
00572 const void **act,
00573 int skip_close)
00574 {
00575 ACE_TRACE ("ACE_Timer_Wheel_T::cancel");
00576 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00577 ACE_Timer_Node_T<TYPE>* n = this->find_node (timer_id);
00578 if (n != 0)
00579 {
00580 ACE_Time_Value last = n->get_timer_value ();
00581 int recalc = (this->get_first_i () == n);
00582 if (act != 0)
00583 *act = n->get_act ();
00584 this->cancel_i (n, skip_close);
00585 if (recalc)
00586 this->recalc_earliest (last);
00587 return 1;
00588 }
00589 return 0;
00590 }
00591
00592
00593 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00594 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::cancel_i (ACE_Timer_Node_T<TYPE>* n, int skip_close)
00595 {
00596
00597 this->unlink (n);
00598 this->free_node (n);
00599 if (!skip_close)
00600 this->upcall_functor ().cancellation (*this, n->get_type ());
00601 }
00602
00603
00604
00605
00606
00607
00608
00609 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00610 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::recalc_earliest
00611 (const ACE_Time_Value& last)
00612 {
00613
00614 if (this->is_empty ())
00615 return;
00616
00617 ACE_Time_Value et = ACE_Time_Value::zero;
00618
00619 u_int spoke = this->earliest_spoke_;
00620
00621
00622 for (u_int i = 0; i < this->spoke_count_; ++i)
00623 {
00624 ACE_Timer_Node_T<TYPE>* root = this->spokes_[spoke];
00625 ACE_Timer_Node_T<TYPE>* n = root->get_next ();
00626 if (n != root)
00627 {
00628 ACE_Time_Value t = n->get_timer_value ();
00629 if (t < last + this->wheel_time_)
00630 {
00631 this->earliest_spoke_ = spoke;
00632 return;
00633 }
00634 else if (et == ACE_Time_Value::zero || t < et)
00635 {
00636 et = t;
00637 }
00638 }
00639 if (++spoke >= this->spoke_count_)
00640 spoke = 0;
00641 }
00642
00643 }
00644
00645
00646
00647
00648
00649 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00650 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::dump (void) const
00651 {
00652 ACE_TRACE ("ACE_Timer_Wheel_T::dump");
00653 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00654
00655 ACE_DEBUG ((LM_DEBUG,
00656 ACE_LIB_TEXT ("\nspoke_count_ = %d"), this->spoke_count_));
00657 ACE_DEBUG ((LM_DEBUG,
00658 ACE_LIB_TEXT ("\nresolution_ = %d"), 1 << this->res_bits_));
00659 ACE_DEBUG ((LM_DEBUG,
00660 ACE_LIB_TEXT ("\nwheel_ = \n")));
00661
00662 for (u_int i = 0; i < this->spoke_count_; ++i)
00663 {
00664 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("%d\n"), i));
00665 ACE_Timer_Node_T<TYPE>* root = this->spokes_[i];
00666 for (ACE_Timer_Node_T<TYPE>* n = root->get_next ();
00667 n != root;
00668 n = n->get_next ())
00669 {
00670 n->dump ();
00671 }
00672 }
00673
00674 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00675 }
00676
00677
00678
00679
00680
00681
00682
00683 template <class TYPE, class FUNCTOR, class ACE_LOCK> ACE_Timer_Node_T<TYPE> *
00684 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::remove_first (void)
00685 {
00686 ACE_TRACE ("ACE_Timer_Wheel_T::remove_first");
00687 return remove_first_expired (ACE_Time_Value::max_time);
00688 }
00689
00690 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00691 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::unlink (ACE_Timer_Node_T<TYPE>* n)
00692 {
00693 ACE_TRACE ("ACE_Timer_Wheel_T::unlink");
00694 --timer_count_;
00695 n->get_prev ()->set_next (n->get_next ());
00696 n->get_next ()->set_prev (n->get_prev ());
00697 n->set_prev (0);
00698 n->set_next (0);
00699 }
00700
00701 template <class TYPE, class FUNCTOR, class ACE_LOCK> ACE_Timer_Node_T<TYPE> *
00702 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::remove_first_expired (const ACE_Time_Value& now)
00703 {
00704 ACE_Timer_Node_T<TYPE>* n = this->get_first ();
00705 if (n != 0 && n->get_timer_value() <= now)
00706 {
00707 this->unlink (n);
00708 this->recalc_earliest (n->get_timer_value ());
00709 return n;
00710 }
00711 return 0;
00712 }
00713
00714
00715
00716
00717
00718
00719 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00720 ACE_Timer_Node_T<TYPE>*
00721 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::get_first (void)
00722 {
00723 ACE_TRACE ("ACE_Timer_Wheel_T::get_first");
00724 return this->get_first_i ();
00725 }
00726
00727 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00728 ACE_Timer_Node_T<TYPE>*
00729 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::get_first_i (void) const
00730 {
00731 ACE_Timer_Node_T<TYPE>* root = this->spokes_[this->earliest_spoke_];
00732 ACE_Timer_Node_T<TYPE>* first = root->get_next ();
00733 if (first != root)
00734 return first;
00735 return 0;
00736 }
00737
00738
00739
00740
00741
00742 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00743 ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>&
00744 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::iter (void)
00745 {
00746 this->iterator_->first ();
00747 return *this->iterator_;
00748 }
00749
00750
00751
00752
00753
00754 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00755 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::expire ()
00756 {
00757 return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire ();
00758 }
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00769 ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::expire (const ACE_Time_Value& cur_time)
00770 {
00771 ACE_TRACE ("ACE_Timer_Wheel_T::expire");
00772 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00773
00774 int expcount = 0;
00775 ACE_Timer_Node_T<TYPE>* n = this->remove_first_expired (cur_time);
00776
00777 while (n != 0)
00778 {
00779 ++ expcount;
00780
00781
00782
00783 this->upcall (n->get_type (), n->get_act (), cur_time);
00784
00785 if (n->get_interval () > ACE_Time_Value::zero)
00786 {
00787 n->set_timer_value (cur_time + n->get_interval ());
00788 this->reschedule (n);
00789 }
00790 else
00791 {
00792 this->free_node (n);
00793 }
00794
00795 n = this->remove_first_expired (cur_time);
00796 }
00797
00798
00799
00800 return expcount;
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00813 ACE_Timer_Wheel_Iterator_T<TYPE,FUNCTOR,ACE_LOCK>::ACE_Timer_Wheel_Iterator_T
00814 (Wheel& wheel)
00815 : timer_wheel_ (wheel)
00816 {
00817 this->first();
00818 }
00819
00820
00821
00822
00823
00824 template <class TYPE, class FUNCTOR, class ACE_LOCK>
00825 ACE_Timer_Wheel_Iterator_T<TYPE,
00826 FUNCTOR,
00827 ACE_LOCK>::~ACE_Timer_Wheel_Iterator_T (void)
00828 {
00829 }
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00841 ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>::first (void)
00842 {
00843 this->goto_next(0);
00844 }
00845
00846
00847
00848
00849
00850 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00851 ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>::next (void)
00852 {
00853 if (this->isdone())
00854 return;
00855
00856 ACE_Timer_Node_T<TYPE>* n = this->current_node_->get_next ();
00857 ACE_Timer_Node_T<TYPE>* root = this->timer_wheel_.spokes_[this->spoke_];
00858 if (n == root)
00859 this->goto_next (this->spoke_ + 1);
00860 else
00861 this->current_node_ = n;
00862 }
00863
00864
00865 template <class TYPE, class FUNCTOR, class ACE_LOCK> void
00866 ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>::goto_next (u_int start_spoke)
00867 {
00868
00869 u_int sc = this->timer_wheel_.spoke_count_;
00870 for (u_int i = start_spoke; i < sc; ++i)
00871 {
00872 ACE_Timer_Node_T<TYPE>* root = this->timer_wheel_.spokes_[i];
00873 ACE_Timer_Node_T<TYPE>* n = root->get_next ();
00874 if (n != root)
00875 {
00876 this->spoke_ = i;
00877 this->current_node_ = n;
00878 return;
00879 }
00880 }
00881
00882 this->spoke_ = sc;
00883 this->current_node_ = 0;
00884 }
00885
00886
00887
00888
00889
00890 template <class TYPE, class FUNCTOR, class ACE_LOCK> int
00891 ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>::isdone (void) const
00892 {
00893 return this->current_node_ == 0;
00894 }
00895
00896
00897
00898
00899
00900
00901 template <class TYPE, class FUNCTOR, class ACE_LOCK> ACE_Timer_Node_T<TYPE> *
00902 ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK>::item (void)
00903 {
00904 return this->current_node_;
00905 }
00906
00907
00908 #endif