sd-event: add destroy callback logic to sd-event too
This adds what has been added to sd_bus_slot and sd_bus_track to sd_event too.
This commit is contained in:
@@ -569,4 +569,6 @@ global:
|
||||
sd_bus_track_set_destroy_callback;
|
||||
sd_event_add_inotify;
|
||||
sd_event_source_get_inotify_mask;
|
||||
sd_event_source_set_destroy_callback;
|
||||
sd_event_source_get_destroy_callback;
|
||||
} LIBSYSTEMD_238;
|
||||
|
||||
@@ -106,6 +106,8 @@ struct sd_event_source {
|
||||
uint64_t pending_iteration;
|
||||
uint64_t prepare_iteration;
|
||||
|
||||
sd_event_destroy_t destroy_callback;
|
||||
|
||||
LIST_FIELDS(sd_event_source, sources);
|
||||
|
||||
union {
|
||||
@@ -1016,7 +1018,10 @@ static void source_free(sd_event_source *s) {
|
||||
source_disconnect(s);
|
||||
|
||||
if (s->type == SOURCE_IO && s->io.owned)
|
||||
safe_close(s->io.fd);
|
||||
s->io.fd = safe_close(s->io.fd);
|
||||
|
||||
if (s->destroy_callback)
|
||||
s->destroy_callback(s->userdata);
|
||||
|
||||
free(s->description);
|
||||
free(s);
|
||||
@@ -3775,3 +3780,19 @@ _public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
|
||||
*ret = e->iteration;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_event_source_set_destroy_callback(sd_event_source *s, sd_event_destroy_t callback) {
|
||||
assert_return(s, -EINVAL);
|
||||
|
||||
s->destroy_callback = callback;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_event_source_get_destroy_callback(sd_event_source *s, sd_event_destroy_t *ret) {
|
||||
assert_return(s, -EINVAL);
|
||||
|
||||
if (ret)
|
||||
*ret = s->destroy_callback;
|
||||
|
||||
return !!s->destroy_callback;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user