]>
Dogcows Code - chaz/yoink/blob - src/moof/timer.hh
d7a411bc48e82089891795db5602d2cfb42e4326
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_TIMER_HH_
13 #define _MOOF_TIMER_HH_
17 * Functions for measuring time in a friendly unit.
22 #include <boost/bind.hpp>
23 #include <boost/function.hpp>
25 #include <moof/math.hh>
43 typedef boost::function
<void(timer
&,scalar
)> function
;
49 timer(const function
& function
, scalar seconds
, mode mode
= normal
)
51 init(function
, seconds
, mode
);
59 void init(const function
& function
, scalar seconds
, mode mode
= normal
);
61 bool is_valid() const;
66 scalar
seconds_remaining() const;
67 bool is_expired() const;
68 bool is_repeating() const;
72 * Get the number of seconds since a fixed, arbitrary point in the
76 static scalar
ticks();
80 * Put the thread to sleep for a certain period of time. If absolute
81 * is true, then it will sleep until seconds after the fixed time in
82 * the past. If absolute is false, it will sleep for seconds starting
83 * now. Unlike system sleep functions, this one automatically resumes
84 * sleep if sleep was interrupted by a signal. Therefore, calling this
85 * function is guaranteed to sleep for the requested amount of time
87 * \param seconds Number of seconds.
88 * \param mode The timer mode.
90 static void sleep(scalar seconds
, mode mode
= normal
);
93 static scalar
next_expiration()
98 static void fire_expired_timers();
99 static void fire_expired_timers(scalar t
);
104 static unsigned new_identifier();
105 static scalar
find_next_expiration();
113 static scalar gNextFire
;
114 static std::map
<unsigned,timer
*> gTimers
;
120 #endif // _MOOF_TIMER_HH_
This page took 0.035944 seconds and 3 git commands to generate.