summaryrefslogtreecommitdiff
path: root/src/common/loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/loop.c')
-rw-r--r--src/common/loop.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/common/loop.c b/src/common/loop.c
index 18d62b1..1c6a612 100644
--- a/src/common/loop.c
+++ b/src/common/loop.c
@@ -199,11 +199,9 @@ static void timer_cleanup_deleted(struct yasl_loop *l)
if (!l || l->timer_firing_depth > 0) return;
int dest = 0;
for (int src = 0; src < l->timer_count; src++) {
- if (!l->timers[src].deleted) {
- if (dest != src)
- l->timers[dest] = l->timers[src];
- dest++;
- }
+ struct yasl_timer_source t = l->timers[src];
+ l->timers[dest] = t;
+ dest += !t.deleted;
}
l->timer_count = dest;
}
@@ -270,11 +268,16 @@ yasl_timer_id yasl_loop_add_timer(struct yasl_loop *l, uint64_t interval_ns,
bool yasl_loop_del_timer(struct yasl_loop *l, yasl_timer_id id)
{
if (!l || id == 0) return false;
- for (int i = 0; i < l->timer_count; i++) {
+ for (int i = l->timer_count - 1; i >= 0; i--) {
if (l->timers[i].id == id && !l->timers[i].deleted) {
l->timers[i].deleted = true;
if (l->timer_firing_depth == 0) {
- timer_cleanup_deleted(l);
+ if (i == l->timer_count - 1) {
+ while (l->timer_count > 0 && l->timers[l->timer_count - 1].deleted)
+ l->timer_count--;
+ } else {
+ timer_cleanup_deleted(l);
+ }
}
return true;
}