Timer: do not clear timers restarted from their own callback function
This commit is contained in:
@@ -45,6 +45,8 @@ struct _timeout {
|
|||||||
multi_timeout *multi_timeout;
|
multi_timeout *multi_timeout;
|
||||||
timeout **self;
|
timeout **self;
|
||||||
gboolean expired;
|
gboolean expired;
|
||||||
|
// timer has been restarted from its own callback function
|
||||||
|
gboolean reactivated;
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout *t);
|
void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout *t);
|
||||||
@@ -158,7 +160,9 @@ void handle_expired_timers()
|
|||||||
if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) {
|
if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) {
|
||||||
// it's time for the callback function
|
// it's time for the callback function
|
||||||
t->expired = t->interval_msec == 0;
|
t->expired = t->interval_msec == 0;
|
||||||
|
t->reactivated = FALSE;
|
||||||
t->_callback(t->arg);
|
t->_callback(t->arg);
|
||||||
|
if (!t->reactivated) {
|
||||||
// If _callback() calls stop_timeout(t) the timer 't' was freed and is not in the timeout_list
|
// If _callback() calls stop_timeout(t) the timer 't' was freed and is not in the timeout_list
|
||||||
if (g_slist_find(timeout_list, t)) {
|
if (g_slist_find(timeout_list, t)) {
|
||||||
// Timer still exists
|
// Timer still exists
|
||||||
@@ -172,6 +176,7 @@ void handle_expired_timers()
|
|||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -208,6 +213,7 @@ void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(),
|
|||||||
can_align = align_with_existing_timeouts(t);
|
can_align = align_with_existing_timeouts(t);
|
||||||
if (!can_align)
|
if (!can_align)
|
||||||
timeout_list = g_slist_insert_sorted(timeout_list, t, compare_timeouts);
|
timeout_list = g_slist_insert_sorted(timeout_list, t, compare_timeouts);
|
||||||
|
t->reactivated = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint compare_timeouts(gconstpointer t1, gconstpointer t2)
|
gint compare_timeouts(gconstpointer t1, gconstpointer t2)
|
||||||
|
|||||||
Reference in New Issue
Block a user