}
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_event, sd_event, event_free);
+#define PROTECT_EVENT(e) \
+ _unused_ _cleanup_(sd_event_unrefp) sd_event *_ref = sd_event_ref(e);
_public_ sd_event_source* sd_event_source_disable_unref(sd_event_source *s) {
if (s)
}
static int source_dispatch(sd_event_source *s) {
- _cleanup_(sd_event_unrefp) sd_event *saved_event = NULL;
EventSourceType saved_type;
+ sd_event *saved_event;
int r = 0;
assert(s);
/* Similarly, store a reference to the event loop object, so that we can still access it after the
* callback might have invalidated/disconnected the event source. */
- saved_event = sd_event_ref(s->event);
+ saved_event = s->event;
+ PROTECT_EVENT(saved_event);
/* Check if we hit the ratelimit for this event source, and if so, let's disable it. */
assert(!s->ratelimited);
return 0;
}
- _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e);
+ PROTECT_EVENT(e);
e->iteration++;
e->state = SD_EVENT_EXITING;
r = source_dispatch(p);
assert_return(!e->default_event_ptr || e->tid == gettid(), -EREMOTEIO);
/* Make sure that none of the preparation callbacks ends up freeing the event source under our feet */
- _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e);
+ PROTECT_EVENT(e);
if (e->exit_requested)
goto pending;
p = event_next_pending(e);
if (p) {
- _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e);
+ PROTECT_EVENT(e);
e->state = SD_EVENT_RUNNING;
r = source_dispatch(p);
}
/* Make sure that none of the preparation callbacks ends up freeing the event source under our feet */
- _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e);
+ PROTECT_EVENT(e);
r = sd_event_prepare(e);
if (r == 0)
assert_return(!event_pid_changed(e), -ECHILD);
assert_return(e->state == SD_EVENT_INITIAL, -EBUSY);
- _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e);
+ PROTECT_EVENT(e);
while (e->state != SD_EVENT_FINISHED) {
r = sd_event_run(e, UINT64_MAX);