libassa  3.5.1
TimerQueue.cpp
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // TimerQueue.cpp
4 //------------------------------------------------------------------------------
5 // Copyright (c) 2000,2005 by Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 //------------------------------------------------------------------------------
13 // Created: 07/28/99
14 //------------------------------------------------------------------------------
15 
16 #include "assa/TimerQueue.h"
17 using namespace ASSA;
18 
21 {
22  trace_with_mask("TimerQueue::~TimerQueue",REACTTRACE);
23 
24  while (m_queue.size ()) {
25  delete m_queue.pop ();
26  }
27 }
28 
29 int
32 {
33  // Like STL iterators, after deletion of an element,
34  // queue structure and indexing might drastically change
35  // and there is no guarantee that elements we haven't seen
36  // yet will not be moved past the iterator. Therefore,
37  // we must start scanning from the beginning after each deletion :-(
38 
39  trace_with_mask("TimerQueue::remove(eh_)",REACTTRACE);
40 
41  register size_t i;
42  int cnt = 0;
43  bool f = true; // changed flag
44  register Timer* tmr;
45 
46  DL((REACT,"Searching for Timer: 0x%x\n", dynamic_cast<void*> (eh_)));
47 
48  while (f) {
49  f = false;
50  DL((REACT,"Queue size: %d\n", m_queue.size()));
51  for (i = 0; i < m_queue.size (); i++) {
52  if (m_queue[i]->getHandler() == eh_) {
53  DL((REACT,"Found Timer: 0x%x in slot: %d\n",
54  dynamic_cast<void*>(eh_), i));
55  tmr = m_queue[i];
56  m_queue.remove (tmr);
57  delete tmr;
58  cnt++;
59  f = true;
60  }
61  }
62  }
63  return cnt;
64 }
65 
66 bool
69 {
70  trace_with_mask("TimerQueue::remove(tid)",REACTTRACE);
71  register size_t i;
72 
73  DL((REACTTRACE,"Queue size before remove: %d\n", m_queue.size()));
74 
75  for (i = 0; i < m_queue.size (); i++) {
76  if (m_queue[i] == (Timer*) tid_) {
77  Timer* tmr = m_queue[i];
78  int ret = m_queue.remove (tmr);
79  delete tmr;
80  DL((REACTTRACE,"Queue size after remove: %d\n", m_queue.size()));
81  return ret;
82  }
83  }
84  return false;
85 }
86 
87 int
89 expire (const TimeVal& tv_)
90 {
91  trace_with_mask("TimerQueue::expire",REACTTRACE);
92 
93  register Timer* tp = (Timer*) NULL;
94  register int cnt = 0;
95 
96  while (m_queue.size () && (tp = m_queue.top ()) != (Timer*) NULL) {
f7d825cd2187ceca287c2cb07ad7587175edc726535df02274693f8d3f">REACTTRACE);
RETtrace_with_mask(
Definition: // changed flag
78  trace_with_mask("TimerQueue::rema>*) NULL) {
97  if (tp->clear (fd_);
 { eft" align="ridineno"> 195  SigSet
21 #include <iostream>
22 
23 #include "assa/Logger_Impl.h"
24}a;
25  53 }
44  ce 6panicroseconds (=1/1,000,000 sec) to millisecnds (=1/comment">// we must start scanning from the beginning after each deletion :-(0/a>
21 25  80
class="lineno"> 70  m_tuple_pttrn.Singleton.h c1b2fdb3c27f890">unbuffered (operator! () const;
303 
30merQueue.html#a0d54611735bd91fe23eb="line">int
Singleton.eLogger.klissASSA_1_1Regexp_html_a12abad0;Singleton.eLogger.klisSocketbuf.html#a088010285d92e8a070a4f8e7c4b64607">Socketbuf::<">ASSA::ServiceHad-classes"> Cl/a> 87 int
376 
243  3>  <"lineno"> 76 pan> 376 
24v class="line">int
13 // Cr------------------------
12 // Created: 12/02/1999m_fd, F_GETFL, 0)) < 0) {
94  register int cnt = 0;
95 
;
TimeVal.h:35
24v class="line">true; // changed flag
44  register Timer* tmr;
STRMBUF 76  if (<261f1a765eae5a1ab9c72b9e0b7"> 24v class="line">true; // changed flag
44  register Timer* tmr;