/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-***/
#include "sd-bus.h"
return slot;
}
-_public_ sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot) {
-
- if (!slot)
- return NULL;
-
- assert(slot->n_ref > 0);
-
- slot->n_ref++;
- return slot;
-}
-
-void bus_slot_disconnect(sd_bus_slot *slot) {
+void bus_slot_disconnect(sd_bus_slot *slot, bool unref) {
sd_bus *bus;
assert(slot);
(void) bus_remove_match_internal(slot->bus, slot->match_callback.match_string);
if (slot->match_callback.install_slot) {
- bus_slot_disconnect(slot->match_callback.install_slot);
+ bus_slot_disconnect(slot->match_callback.install_slot, true);
slot->match_callback.install_slot = sd_bus_slot_unref(slot->match_callback.install_slot);
}
if (!slot->floating)
sd_bus_unref(bus);
+ else if (unref)
+ sd_bus_slot_unref(slot);
}
-_public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
-
- if (!slot)
- return NULL;
-
- assert(slot->n_ref > 0);
-
- if (slot->n_ref > 1) {
- slot->n_ref--;
- return NULL;
- }
+static sd_bus_slot* bus_slot_free(sd_bus_slot *slot) {
+ assert(slot);
- bus_slot_disconnect(slot);
+ bus_slot_disconnect(slot, false);
if (slot->destroy_callback)
slot->destroy_callback(slot->userdata);
return mfree(slot);
}
+DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus_slot, sd_bus_slot, bus_slot_free);
+
_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
assert_return(slot, NULL);