summaryrefslogtreecommitdiff
path: root/lib/common/Timer.h
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-12-03 13:58:14 +0000
committerChris Wilson <chris+github@qwirx.com>2006-12-03 13:58:14 +0000
commitcff19bd8c52b58095aaf2aa35f38673c29f1aa88 (patch)
treedb721b29a1f290d228805429d3516a486dc13e81 /lib/common/Timer.h
parentbc82918ca28737fc934c33b69e13bb2efb28d89e (diff)
Fixed a race condition caused by rescheduling in signal handler (refs
#3, refs #9)
Diffstat (limited to 'lib/common/Timer.h')
-rw-r--r--lib/common/Timer.h56
1 files changed, 38 insertions, 18 deletions
diff --git a/lib/common/Timer.h b/lib/common/Timer.h
index e0eb34db..390442df 100644
--- a/lib/common/Timer.h
+++ b/lib/common/Timer.h
@@ -18,23 +18,7 @@
#include "MemLeakFindOn.h"
#include "BoxTime.h"
-class Timer
-{
-public:
- Timer(size_t timeoutSecs);
- virtual ~Timer();
- Timer(const Timer &);
- Timer &operator=(const Timer &);
-
-public:
- box_time_t GetExpiryTime() { return mExpires; }
- bool HasExpired () { return mExpired; }
- virtual void OnExpire ();
-
-private:
- box_time_t mExpires;
- bool mExpired;
-};
+class Timer;
// --------------------------------------------------------------------------
//
@@ -50,13 +34,49 @@ class Timers
private:
static std::vector<Timer*>* spTimers;
static void Reschedule();
+
+ static bool sRescheduleNeeded;
+ static void SignalHandler(int iUnused);
public:
static void Init();
static void Cleanup();
static void Add (Timer& rTimer);
static void Remove(Timer& rTimer);
- static void Signal();
+ static void RequestReschedule()
+ {
+ sRescheduleNeeded = true;
+ }
+
+ static void RescheduleIfNeeded()
+ {
+ if (sRescheduleNeeded)
+ {
+ Reschedule();
+ }
+ }
+};
+
+class Timer
+{
+public:
+ Timer(size_t timeoutSecs);
+ virtual ~Timer();
+ Timer(const Timer &);
+ Timer &operator=(const Timer &);
+
+public:
+ box_time_t GetExpiryTime() { return mExpires; }
+ virtual void OnExpire();
+ bool HasExpired()
+ {
+ Timers::RescheduleIfNeeded();
+ return mExpired;
+ }
+
+private:
+ box_time_t mExpires;
+ bool mExpired;
};
#include "MemLeakFindOff.h"