diff options
author | Michal Bloch <m.bloch@samsung.com> | 2022-07-21 22:55:56 +0200 |
---|---|---|
committer | Michal Bloch <m.bloch@samsung.com> | 2022-07-21 23:34:50 +0200 |
commit | 74a29f46bc69f99983cb4e9d5825f57d32787631 (patch) | |
tree | 143c678048126656b08026d2222aaa39d31f2ac8 | |
parent | 9c9f9b14abab3812baa097c15ea9adb9450c6d69 (diff) | |
download | sessiond-74a29f46bc69f99983cb4e9d5825f57d32787631.tar.gz sessiond-74a29f46bc69f99983cb4e9d5825f57d32787631.tar.bz2 sessiond-74a29f46bc69f99983cb4e9d5825f57d32787631.zip |
library: simplify logic in callback_data functions
Change-Id: I6f707a201780012a3c138fca85f7a0d0b9f9a26c
-rw-r--r-- | libsessiond/src/lib.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/libsessiond/src/lib.c b/libsessiond/src/lib.c index 4960789..f50fbba 100644 --- a/libsessiond/src/lib.c +++ b/libsessiond/src/lib.c @@ -329,15 +329,19 @@ static gint g_compare_addremove_signal(gconstpointer lval, gconstpointer rval) static signal_client_data_t *callbacks_data_pop(client_callbacks_data_t *client_callbacks_data, gconstpointer parameters, GCompareFunc compare_user_params) { + assert(client_callbacks_data); + assert(compare_user_params); + + g_mutex_lock(&client_callbacks_data->mutex); signal_client_data_t *signal_data = NULL; + GList *found_data = g_list_find_custom(client_callbacks_data->list, parameters, compare_user_params); + if (found_data != NULL) { + assert(found_data->data); + signal_data = (signal_client_data_t *)found_data->data; + client_callbacks_data->list = g_list_remove(client_callbacks_data->list, found_data->data); + } - g_mutex_lock(&client_callbacks_data->mutex); - GList *found_data = g_list_find_custom( client_callbacks_data->list, (gconstpointer) parameters, compare_user_params ); - if (found_data != NULL && found_data->data != NULL) { - signal_data = (signal_client_data_t*)found_data->data; - client_callbacks_data->list = g_list_remove(client_callbacks_data->list, found_data->data); - } g_mutex_unlock(&client_callbacks_data->mutex); return signal_data; @@ -345,15 +349,16 @@ static signal_client_data_t *callbacks_data_pop(client_callbacks_data_t *client_ static signal_client_data_t *callbacks_data_find(client_callbacks_data_t *client_callbacks_data, gconstpointer parameters, GCompareFunc compare_user_params) { - signal_client_data_t *signal_data = NULL; + assert(client_callbacks_data); + assert(compare_user_params); g_mutex_lock(&client_callbacks_data->mutex); - GList *found_data = g_list_find_custom( client_callbacks_data->list, (gconstpointer) parameters, compare_user_params ); - if (found_data != NULL && found_data->data != NULL) { - signal_data = (signal_client_data_t*)found_data->data; - } + + GList *found_data = g_list_find_custom(client_callbacks_data->list, parameters, compare_user_params); + g_mutex_unlock(&client_callbacks_data->mutex); - return signal_data; + + return found_data ? (signal_client_data_t *)found_data->data : NULL; } static bool signal_handler_internal(const gchar *signal_name, |