aboutsummaryrefslogtreecommitdiff
path: root/backends/timer/default
diff options
context:
space:
mode:
Diffstat (limited to 'backends/timer/default')
-rw-r--r--backends/timer/default/default-timer.cpp43
-rw-r--r--backends/timer/default/default-timer.h6
2 files changed, 10 insertions, 39 deletions
diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp
index 907c715a07..245291c06c 100644
--- a/backends/timer/default/default-timer.cpp
+++ b/backends/timer/default/default-timer.cpp
@@ -25,61 +25,34 @@
#include "common/util.h"
#include "common/system.h"
-namespace Common {
-// FIXME: Hack: This global variable shouldn't be declared here; in fact it
-// probably shouldn't be declared at all but rather a different method to
-// query the TimerManager object should be invented.
-TimerManager *g_timer = NULL;
-}
-
-DefaultTimerManager::DefaultTimerManager(OSystem *system) :
- _system(system),
+DefaultTimerManager::DefaultTimerManager() :
_timerHandler(0),
_lastTime(0) {
- Common::g_timer = this;
-
for (int i = 0; i < MAX_TIMERS; i++) {
_timerSlots[i].procedure = NULL;
_timerSlots[i].interval = 0;
_timerSlots[i].counter = 0;
}
- _thisTime = _system->getMillis();
-
- // Set the timer last, after everything has been initialised
- _system->setTimerCallback(&timer_handler, 10);
-
+ _thisTime = g_system->getMillis();
}
DefaultTimerManager::~DefaultTimerManager() {
- // Remove the timer callback.
- // Note: backends *must* gurantee that after this method call returns,
- // the handler is not in use anymore; else race condtions could occur.
- _system->setTimerCallback(0, 0);
-
- {
- Common::StackLock lock(_mutex);
- for (int i = 0; i < MAX_TIMERS; i++) {
- _timerSlots[i].procedure = NULL;
- _timerSlots[i].interval = 0;
- _timerSlots[i].counter = 0;
- }
+ Common::StackLock lock(_mutex);
+ for (int i = 0; i < MAX_TIMERS; i++) {
+ _timerSlots[i].procedure = NULL;
+ _timerSlots[i].interval = 0;
+ _timerSlots[i].counter = 0;
}
}
-int DefaultTimerManager::timer_handler(int t) {
- if (Common::g_timer)
- return ((DefaultTimerManager *)Common::g_timer)->handler(t);
- return 0;
-}
-
int DefaultTimerManager::handler(int t) {
Common::StackLock lock(_mutex);
uint32 interval, l;
_lastTime = _thisTime;
- _thisTime = _system->getMillis();
+ _thisTime = g_system->getMillis();
interval = 1000 * (_thisTime - _lastTime);
for (l = 0; l < MAX_TIMERS; l++) {
diff --git a/backends/timer/default/default-timer.h b/backends/timer/default/default-timer.h
index 12779cc59c..8c16122b02 100644
--- a/backends/timer/default/default-timer.h
+++ b/backends/timer/default/default-timer.h
@@ -32,7 +32,6 @@ private:
enum {
MAX_TIMERS = 8
};
- OSystem *_system;
Common::Mutex _mutex;
void *_timerHandler;
int32 _thisTime;
@@ -46,13 +45,12 @@ private:
} _timerSlots[MAX_TIMERS];
public:
- DefaultTimerManager(OSystem *system);
+ DefaultTimerManager();
~DefaultTimerManager();
bool installTimerProc(TimerProc proc, int32 interval, void *refCon);
void removeTimerProc(TimerProc proc);
-protected:
- static int timer_handler(int t);
+ // Timer callback, to be invoked at regular time intervals by the backend.
int handler(int t);
};