From 5480e2828a5023f674c4528c1e44a73c6bac1404 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 9 Jun 2023 16:39:19 +0200 Subject: [PATCH] fix(kqueue): use timer ns as kqueue identifier. This fixes actually removing a timer from kqueue. Signed-off-by: Federico Di Pierro --- Lib/core/poll/kqueue.c | 3 +-- TODO.md | 2 ++ tests/test_mod.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/core/poll/kqueue.c b/Lib/core/poll/kqueue.c index 6c8812a8..35a890c9 100644 --- a/Lib/core/poll/kqueue.c +++ b/Lib/core/poll/kqueue.c @@ -21,7 +21,6 @@ int poll_create(poll_priv_t *priv) { } int poll_set_new_evt(poll_priv_t *priv, ev_src_t *tmp, const enum op_type flag) { - static int timer_ids = 1; GET_PRIV_DATA(); /* Eventually alloc kqueue data if needed */ @@ -53,7 +52,7 @@ int poll_set_new_evt(poll_priv_t *priv, ev_src_t *tmp, const enum op_type flag) #else const int flags = 0; // unsupported... #endif - EV_SET(_ev, timer_ids++, EVFILT_TIMER, f, flags | NOTE_NSECONDS, tmp->tmr_src.its.ns, tmp); + EV_SET(_ev, tmp->tmr_src.its.ns, EVFILT_TIMER, f, flags | NOTE_NSECONDS, tmp->tmr_src.its.ns, tmp); break; } case M_SRC_TYPE_SGN: diff --git a/TODO.md b/TODO.md index e0357ea6..8dc318d3 100644 --- a/TODO.md +++ b/TODO.md @@ -12,6 +12,8 @@ ### Src - [x] add an M_SRC_FORCE flag to register_mod_src to force register a src even if the same is already existing (deregistering the old one)? - [x] double check m_bst_insert/remove usage in src API + add unit tests! +- [ ] Impl M_SRC_FORCE for topic too? +- [ ] add a poll_refresh_src API that calls: epoll_ctl with EPOLL_CTL_MOD, or kqueue ADD to refresh an event trigger, instead of removing and adding back the event #### Ctx - [ ] use pthread_setname_np() to store each context thread name (max 16chars len; drop ctx->name field) ? diff --git a/tests/test_mod.c b/tests/test_mod.c index 283e0c4e..0094ebb6 100644 --- a/tests/test_mod.c +++ b/tests/test_mod.c @@ -266,7 +266,7 @@ void test_mod_srcs(void **state) { (void) state; /* unused */ // 1000s just to test - const m_src_tmr_t my_tmr = {.ns = 1000000000000 }; + const m_src_tmr_t my_tmr = {.ns = 5000 }; int ret = m_mod_src_register_tmr(test_mod, &my_tmr, M_SRC_FD_AUTOCLOSE, NULL); assert_true(ret == 0);