timer works as expected
parent
3b1aaf36c2
commit
f89ab91917
|
@ -482,13 +482,16 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event,
|
|||
|
||||
gettimeofday(&tv_2, NULL);
|
||||
|
||||
int new_timer = *timer - ((tv_2.tv_sec - tv_1.tv_sec) * 1000000 + (tv_2.tv_usec - tv_1.tv_usec)) / 1000;
|
||||
int nb_sec_ms = (tv_2.tv_sec - tv_1.tv_sec) * 1000;
|
||||
int nb_usec_ms = (tv_2.tv_usec - tv_1.tv_usec) / 1000;
|
||||
int time_elapsed_ms = (nb_sec_ms + nb_usec_ms);
|
||||
|
||||
// Handle memory fuckery, 'cause low level programming is fun.
|
||||
if (new_timer >= *timer || new_timer < 0) {
|
||||
if (time_elapsed_ms >= *timer) {
|
||||
*timer = 0;
|
||||
}
|
||||
else {
|
||||
*timer = new_timer;
|
||||
*timer -= time_elapsed_ms;
|
||||
}
|
||||
|
||||
// Timeout.
|
||||
|
|
Reference in New Issue