diff --git a/source/bsd/event_loop_kqueue.c b/source/bsd/event_loop_kqueue.c index 2789b74..0f0e659 100644 --- a/source/bsd/event_loop_kqueue.c +++ b/source/bsd/event_loop_kqueue.c @@ -151,10 +151,12 @@ int tlb_evl_handle_events(struct tlb_event_loop *loop, size_t budget, int timeou TLB_LOG_EVENT(sub, "Handling"); + /* Cache this off because sub can become invalid during on_event */ + const bool is_oneshot = sub->sub_mode & TLB_SUB_ONESHOT; sub->oneshot_state = TLB_STATE_RUNNING; sub->on_event(sub, s_events_from_kevent(ev), sub->userdata); - if (sub->sub_mode & TLB_SUB_ONESHOT) { + if (is_oneshot) { switch (sub->oneshot_state) { case TLB_STATE_SUBBED: /* Not possible */ diff --git a/source/linux/event_loop_epoll.c b/source/linux/event_loop_epoll.c index 9551d82..23ee855 100644 --- a/source/linux/event_loop_epoll.c +++ b/source/linux/event_loop_epoll.c @@ -167,11 +167,11 @@ int tlb_evl_handle_events(struct tlb_event_loop *loop, size_t budget, int timeou TLB_LOG_EVENT(sub, "Handling"); /* Cache this off because sub can become invalid during on_event */ - const uint8_t sub_mode = sub->sub_mode; + const bool is_oneshot = sub->sub_mode & TLB_SUB_ONESHOT; sub->oneshot_state = TLB_STATE_RUNNING; sub->on_event(sub, s_events_from_epoll(event), sub->userdata); - if (sub_mode & TLB_SUB_ONESHOT) { + if (is_oneshot) { switch ((enum tlb_sub_state)sub->oneshot_state) { case TLB_STATE_SUBBED: /* Not possible */