mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / src / kernel / blocks / qmgr / timer.hpp
blobd02f4f3a1b7da0e4649a7b9e86bccbdc6677cd61
1 /* Copyright (c) 2003, 2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 /**
17 * @class Timer
18 * @brief A timer class that can't be fooled by NTP:ing the system clock to old time
20 class Timer {
21 public:
22 Timer() {
23 m_delay = 10;
26 Timer(NDB_TICKS delay_time) {
27 m_delay = delay_time;
30 /**
31 * Set/Get alarm time of timer
33 inline void setDelay(NDB_TICKS delay_time) { m_delay = delay_time; }
34 inline NDB_TICKS getDelay() { return m_delay; }
36 /**
37 * Start timer
39 inline void reset() {
40 m_current_time = NdbTick_CurrentMillisecond();
41 m_alarm_time = m_current_time + m_delay;
44 /**
45 * Check for alarm
46 */
47 inline bool check() { return check(NdbTick_CurrentMillisecond()); }
49 inline bool check(NDB_TICKS check_time) {
50 /**
51 * Standard alarm check
53 if (check_time > m_alarm_time) return true;
55 /**
56 * Time progressing, but it is not alarm time yet
58 if (check_time >= m_current_time) return false;
60 /**
61 * Time has moved backwards
63 reset();
64 return false;
67 private:
68 NDB_TICKS m_current_time;
69 NDB_TICKS m_alarm_time;
70 NDB_TICKS m_delay;