1
/* ptwinmm.c -- portable timer implementation for win32 */
11
static long time_offset = 0;
12
static int time_started_flag = FALSE;
13
static long time_resolution;
14
static MMRESULT timer_id;
15
static PtCallback *time_callback;
17
void CALLBACK winmm_time_callback(UINT uID, UINT uMsg, DWORD dwUser,
20
(*time_callback)(Pt_Time(), (void *) dwUser);
24
PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
26
if (time_started_flag) return ptAlreadyStarted;
27
timeBeginPeriod(resolution);
28
time_resolution = resolution;
29
time_offset = timeGetTime();
30
time_started_flag = TRUE;
31
time_callback = callback;
33
timer_id = timeSetEvent(resolution, 1, winmm_time_callback,
34
(DWORD) userData, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
35
if (!timer_id) return ptHostError;
43
if (!time_started_flag) return ptAlreadyStopped;
44
if (time_callback && timer_id) {
45
timeKillEvent(timer_id);
49
time_started_flag = FALSE;
50
timeEndPeriod(time_resolution);
57
return time_started_flag;
63
return timeGetTime() - time_offset;