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:
Lennart Poettering
2018-06-07 13:10:56 +02:00
parent 66223497d0
commit 15723a1db0
5 changed files with 143 additions and 1 deletions
+2
View File
@@ -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;
+22 -1
View File
@@ -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;
}