From a71fe8b8aee1cb78c4d8c56eeb234743f64e4b4d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 15 May 2014 01:55:18 +0200 Subject: sd-event: introduce concept of "floating" event sources These are the counterpart of "floating" bus slots, i.e. event sources that are bound to the lifetime of the event object itself, and thus don't require an explicit reference to be kept. --- src/libsystemd/sd-bus/bus-internal.h | 6 +++--- src/libsystemd/sd-bus/bus-slot.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/libsystemd/sd-bus') diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 042d352261..d1183d69c4 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -126,7 +126,6 @@ struct vtable_member { }; typedef enum BusSlotType { - _BUS_SLOT_DISCONNECTED, BUS_REPLY_CALLBACK, BUS_FILTER_CALLBACK, BUS_MATCH_CALLBACK, @@ -134,14 +133,15 @@ typedef enum BusSlotType { BUS_NODE_ENUMERATOR, BUS_NODE_VTABLE, BUS_NODE_OBJECT_MANAGER, + _BUS_SLOT_INVALID = -1, } BusSlotType; struct sd_bus_slot { unsigned n_ref; sd_bus *bus; void *userdata; - BusSlotType type; - bool floating; + BusSlotType type:5; + bool floating:1; LIST_FIELDS(sd_bus_slot, slots); diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 8e38992ec4..5e927511d5 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -67,12 +67,11 @@ void bus_slot_disconnect(sd_bus_slot *slot) { assert(slot); - switch (slot->type) { - - case _BUS_SLOT_DISCONNECTED: - /* Already disconnected... */ + if (!slot->bus) return; + switch (slot->type) { + case BUS_REPLY_CALLBACK: if (slot->reply_callback.cookie != 0) @@ -181,10 +180,14 @@ void bus_slot_disconnect(sd_bus_slot *slot) { } break; + + default: + assert_not_reached("Wut? Unknown slot type?"); } + bus = slot->bus; - slot->type = _BUS_SLOT_DISCONNECTED; + slot->type = _BUS_SLOT_INVALID; slot->bus = NULL; LIST_REMOVE(slots, bus->slots, slot); @@ -235,7 +238,7 @@ _public_ void *sd_bus_slot_set_userdata(sd_bus_slot *slot, void *userdata) { _public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) { assert_return(slot, NULL); - assert_return(slot->type != _BUS_SLOT_DISCONNECTED, NULL); + assert_return(slot->type >= 0, NULL); if (slot->bus->current_slot != slot) return NULL; -- cgit v1.2.3-54-g00ecf