Skip to content

Commit

Permalink
windows: use waitable timers
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Aug 29, 2024
1 parent d6b676a commit 3cc5a10
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,16 +1064,26 @@ void gral_window_clipboard_paste(gral_window *window, void (*callback)(char cons
CloseClipboard();
}

static void CALLBACK timer_callback(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
gral_timer *timer = (gral_timer *)lpArgToCompletionRoutine;
timer->callback(timer->user_data);
}

gral_timer *gral_window_create_timer(gral_window *window, int milliseconds, void (*callback)(void *user_data), void *user_data) {
gral_timer *timer = new gral_timer();
timer->callback = callback;
timer->user_data = user_data;
SetTimer((HWND)window, (UINT_PTR)timer, milliseconds, NULL);
//SetTimer((HWND)window, (UINT_PTR)timer, milliseconds, NULL);
HANDLE handle = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER due_time;
due_time.QuadPart = milliseconds * -10000;
SetWaitableTimer(handle, &due_time, milliseconds, timer_callback, timer, FALSE);
return timer;
}

void gral_window_delete_timer(gral_window *window, gral_timer *timer) {
KillTimer((HWND)window, (UINT_PTR)timer);
//KillTimer((HWND)window, (UINT_PTR)timer);
//CancelWaitableTimer((HWND)timer);
delete timer;
}

Expand Down

0 comments on commit 3cc5a10

Please sign in to comment.