[Box Backup-commit] COMMIT r1142 - box/chris/merge/lib/win32
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Mon Nov 6 20:45:32 GMT 2006
Author: chris
Date: 2006-11-06 20:45:32 +0000 (Mon, 06 Nov 2006)
New Revision: 1142
Modified:
box/chris/merge/lib/win32/emu.cpp
Log:
Protect against double initialisation of win32 timers
Modified: box/chris/merge/lib/win32/emu.cpp
===================================================================
--- box/chris/merge/lib/win32/emu.cpp 2006-11-06 20:43:12 UTC (rev 1141)
+++ box/chris/merge/lib/win32/emu.cpp 2006-11-06 20:45:32 UTC (rev 1142)
@@ -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 @@
int setitimer(int type, struct itimerval *timeout, void *arg)
{
+ ASSERT(gTimerInitialised);
+
if (ITIMER_VIRTUAL == type)
{
EnterCriticalSection(&gLock);
@@ -131,20 +134,25 @@
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
More information about the Boxbackup-commit
mailing list