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.c59
1 files changed, 4 insertions, 55 deletions
diff --git a/src/common/loop.c b/src/common/loop.c
index a1f2434..3815e91 100644
--- a/src/common/loop.c
+++ b/src/common/loop.c
@@ -1,6 +1,6 @@
#define _GNU_SOURCE
#define _POSIX_C_SOURCE 200809L
-#include "yasl/yasl.h"
+#include "loop.h"
#include <errno.h>
#include <fcntl.h>
@@ -23,16 +23,11 @@ struct yasl_fd_source {
};
struct yasl_timer_source {
- union {
- yasl_timer_cb ns;
- yasl_timer_ms_cb ms;
- void *raw;
- } fn;
+ yasl_timer_cb fn;
void *ud;
yasl_timer_id id;
uint64_t interval_ns;
uint64_t deadline_ns;
- bool ms_mode;
bool deleted;
};
@@ -251,44 +246,11 @@ yasl_timer_id yasl_loop_add_timer(struct yasl_loop *l, uint64_t interval_ns,
uint64_t now = yasl_loop_now_ns();
l->timers[l->timer_count++] = (struct yasl_timer_source){
- .fn.ns = cb,
+ .fn = cb,
.ud = ud,
.id = id,
.interval_ns = interval_ns,
.deadline_ns = now + interval_ns,
- .ms_mode = false,
- .deleted = false,
- };
-
- yasl_loop_kick(l);
- return id;
-}
-
-yasl_timer_id yasl_loop_add_timer_ms(struct yasl_loop *l, uint32_t interval_ms,
- yasl_timer_ms_cb cb, void *ud)
-{
- if (!l || !cb || interval_ms == 0) return 0;
-
- if (l->timer_count >= l->timer_capacity) {
- int new_cap = l->timer_capacity ? l->timer_capacity * 2 : 16;
- struct yasl_timer_source *new_timers = realloc(l->timers, (size_t)new_cap * sizeof(*new_timers));
- if (!new_timers) return 0;
- l->timers = new_timers;
- l->timer_capacity = new_cap;
- }
-
- uint32_t id = l->next_timer_id++;
- if (l->next_timer_id == 0) l->next_timer_id = 1;
-
- uint64_t now = yasl_loop_now_ns();
- uint64_t interval_ns = (uint64_t)interval_ms * 1000000ull;
- l->timers[l->timer_count++] = (struct yasl_timer_source){
- .fn.ms = cb,
- .ud = ud,
- .id = id,
- .interval_ns = interval_ns,
- .deadline_ns = now + interval_ns,
- .ms_mode = true,
.deleted = false,
};
@@ -390,18 +352,10 @@ int yasl_loop_step(struct yasl_loop *l, int timeout_ms)
yasl_timer_id tid = l->timers[i].id;
uint64_t interval = l->timers[i].interval_ns;
- bool is_ms = l->timers[i].ms_mode;
void *ud = l->timers[i].ud;
struct yasl_timer_source timer_src = l->timers[i];
- uint64_t next_interval = 0;
- if (is_ms) {
- uint32_t old_ms = (uint32_t)(interval / 1000000ull);
- uint32_t res_ms = timer_src.fn.ms(ud, tid, old_ms);
- next_interval = (uint64_t)res_ms * 1000000ull;
- } else {
- next_interval = timer_src.fn.ns(ud, tid, interval);
- }
+ uint64_t next_interval = timer_src.fn(ud, tid, interval);
handled++;
for (int j = 0; j < l->timer_count; j++) {
@@ -443,8 +397,3 @@ void yasl_loop_quit(struct yasl_loop *l)
{
if (l) l->running = false;
}
-
-bool yasl_loop_is_running(const struct yasl_loop *l)
-{
- return l ? l->running : false;
-}