annotate src/timer.c @ 9:07f0e2f43204

*: add the restrict keyword when necessary also fixed some typos in the README
author Paper
date Fri, 16 Dec 2022 21:55:37 -0500
parents be4835547dd0
children 42ac054c0231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include <assert.h>
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #ifndef WIN32_LEAN_AND_MEAN
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 # define WIN32_LEAN_AND_MEAN
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #endif
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <windows.h>
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "timer.h"
1
7abb5d8b20ea Initial commit: part 2
Paper <mrpapersonic@gmail.com>
parents: 0
diff changeset
7
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
8 void timer_init(struct timer* restrict timer, HWND winampClientWindow, TIMERPROC timer_proc) {
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 timer->winampClientWindow = winampClientWindow;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 timer->timer_proc = timer_proc;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 timer->initialized = 1;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 }
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
14 void timer_set(struct timer* restrict timer, HWND winampClientWindow) {
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 assert(timer->initialized);
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
16
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 if (timer->is_timer_alive)
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 return;
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
19
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 timer->is_timer_alive = 1;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 SetTimer(winampClientWindow, 1, timer->interval, timer->timer_proc);
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 }
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
24 void timer_stop(struct timer* restrict timer, HWND winampClientWindow) {
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 assert(timer->initialized);
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
26
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 if (!timer->is_timer_alive)
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 return;
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
29
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 timer->is_timer_alive = 0;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 KillTimer(winampClientWindow, 1);
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 }