summaryrefslogtreecommitdiff
path: root/lib/win32
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-11-06 20:45:32 +0000
committerChris Wilson <chris+github@qwirx.com>2006-11-06 20:45:32 +0000
commit45a95c864a32098eb9ac73b9c5fec1fa25061f3d (patch)
treecc6982d772db6332b3e81f9a2c0de712ae6d7e65 /lib/win32
parent3a590d43ce5e108e42483993b3ce7bfaaa20d74d (diff)
Protect against double initialisation of win32 timers
Diffstat (limited to 'lib/win32')
-rw-r--r--lib/win32/emu.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index 6ce1790c..205ada9b 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -28,6 +28,7 @@
// our implementation for a timer, based on a
// simple thread which sleeps for a period of time
+static bool gTimerInitialised = false;
static bool gFinishTimer;
static CRITICAL_SECTION gLock;
@@ -43,6 +44,8 @@ static void (__cdecl *gTimerFunc) (int) = NULL;
int setitimer(int type, struct itimerval *timeout, void *arg)
{
+ ASSERT(gTimerInitialised);
+
if (ITIMER_VIRTUAL == type)
{
EnterCriticalSection(&gLock);
@@ -131,20 +134,25 @@ int SetTimerHandler(void (__cdecl *func ) (int))
void InitTimer(void)
{
+ ASSERT(!gTimerInitialised);
InitializeCriticalSection(&gLock);
-
+
// create our thread
HANDLE ourThread = (HANDLE)_beginthreadex(NULL, 0, RunTimer, 0,
CREATE_SUSPENDED, NULL);
SetThreadPriority(ourThread, THREAD_PRIORITY_LOWEST);
ResumeThread(ourThread);
+
+ gTimerInitialised = true;
}
void FiniTimer(void)
{
+ ASSERT(gTimerInitialised);
gFinishTimer = true;
EnterCriticalSection(&gLock);
DeleteCriticalSection(&gLock);
+ gTimerInitialised = false;
}
//Our constants we need to keep track of