bus: optionally call a callbacks for cleanup

This adds a function sd_bus_slot_set_destroy_callback() to set a function
which can free userdata or perform other cleanups.

sd_bus_slot_get_destory_callback() queries the callback, and is included
for completeness.

Without something like this, for floating asynchronous callbacks, which might
be called or not, depending on the sequence of events, it's hard to perform
resource cleanup. The alternative would be to always perform the cleanup from
the caller too, but that requires more coordination and keeping of some shared
state. It's nicer to keep the cleanup contained between the callback and the
function that requests the callback.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-06-06 23:01:57 +02:00
parent e3736e0223
commit fa17b4e8d9
7 changed files with 136 additions and 0 deletions
+2
View File
@@ -563,6 +563,8 @@ global:
sd_bus_open_system_with_description;
sd_bus_slot_get_floating;
sd_bus_slot_set_floating;
sd_bus_slot_get_destroy_callback;
sd_bus_slot_set_destroy_callback;
sd_event_add_inotify;
sd_event_source_get_inotify_mask;
} LIBSYSTEMD_238;