mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-27 08:00:06 +01:00
Make ref count unref/ref() functions return resulting object pointer
In order to know if an unref() destroyed an object and to allow more convenient use of ref(), make both functions return a pointer to the object it was passed, or NULL if that object was destroyed. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
82e81e8790
commit
13e9a1d744
2 changed files with 24 additions and 10 deletions
|
|
@ -607,10 +607,11 @@ libinput_seat_init(struct libinput_seat *seat,
|
|||
list_insert(&libinput->seat_list, &seat->link);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT void
|
||||
LIBINPUT_EXPORT struct libinput_seat *
|
||||
libinput_seat_ref(struct libinput_seat *seat)
|
||||
{
|
||||
seat->refcount++;
|
||||
return seat;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -622,13 +623,17 @@ libinput_seat_destroy(struct libinput_seat *seat)
|
|||
seat->destroy(seat);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT void
|
||||
LIBINPUT_EXPORT struct libinput_seat *
|
||||
libinput_seat_unref(struct libinput_seat *seat)
|
||||
{
|
||||
assert(seat->refcount > 0);
|
||||
seat->refcount--;
|
||||
if (seat->refcount == 0)
|
||||
if (seat->refcount == 0) {
|
||||
libinput_seat_destroy(seat);
|
||||
return NULL;
|
||||
} else {
|
||||
return seat;
|
||||
}
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT void
|
||||
|
|
@ -663,10 +668,11 @@ libinput_device_init(struct libinput_device *device,
|
|||
device->refcount = 1;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT void
|
||||
LIBINPUT_EXPORT struct libinput_device *
|
||||
libinput_device_ref(struct libinput_device *device)
|
||||
{
|
||||
device->refcount++;
|
||||
return device;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -675,13 +681,17 @@ libinput_device_destroy(struct libinput_device *device)
|
|||
evdev_device_destroy((struct evdev_device *) device);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT void
|
||||
LIBINPUT_EXPORT struct libinput_device *
|
||||
libinput_device_unref(struct libinput_device *device)
|
||||
{
|
||||
assert(device->refcount > 0);
|
||||
device->refcount--;
|
||||
if (device->refcount == 0)
|
||||
if (device->refcount == 0) {
|
||||
libinput_device_destroy(device);
|
||||
return NULL;
|
||||
} else {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT int
|
||||
|
|
|
|||
|
|
@ -1080,8 +1080,9 @@ libinput_log_set_handler(libinput_log_handler log_handler,
|
|||
* the seat correctly to avoid dangling pointers.
|
||||
*
|
||||
* @param seat A previously obtained seat
|
||||
* @return The passed seat
|
||||
*/
|
||||
void
|
||||
struct libinput_seat *
|
||||
libinput_seat_ref(struct libinput_seat *seat);
|
||||
|
||||
/**
|
||||
|
|
@ -1093,8 +1094,9 @@ libinput_seat_ref(struct libinput_seat *seat);
|
|||
* the seat correctly to avoid dangling pointers.
|
||||
*
|
||||
* @param seat A previously obtained seat
|
||||
* @return NULL if seat was destroyed, otherwise the passed seat
|
||||
*/
|
||||
void
|
||||
struct libinput_seat *
|
||||
libinput_seat_unref(struct libinput_seat *seat);
|
||||
|
||||
/**
|
||||
|
|
@ -1167,8 +1169,9 @@ libinput_seat_get_logical_name(struct libinput_seat *seat);
|
|||
* the device correctly to avoid dangling pointers.
|
||||
*
|
||||
* @param device A previously obtained device
|
||||
* @return The passed device
|
||||
*/
|
||||
void
|
||||
struct libinput_device *
|
||||
libinput_device_ref(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
|
|
@ -1180,8 +1183,9 @@ libinput_device_ref(struct libinput_device *device);
|
|||
* the device correctly to avoid dangling pointers.
|
||||
*
|
||||
* @param device A previously obtained device
|
||||
* @return NULL if device was destroyed, otherwise the passed device
|
||||
*/
|
||||
void
|
||||
struct libinput_device *
|
||||
libinput_device_unref(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue