From 2ad0dcdf0158a5ff7b67969ecc6be371e8280665 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 20 Aug 2021 11:02:31 +0900 Subject: [PATCH] device-idler: reduce to a single function, g_idle_add() Change-Id: I95e33e1763d22aeea892836e6417aea78f6d7664 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 - src/core/device-idler.c | 102 -------------------------------------- src/core/device-idler.h | 29 ----------- src/display/display-dbus.c | 9 ++-- src/power/power-handler.c | 1 - src/usb-host-test/usb-host-test.c | 1 - src/usbhost/usb-host.c | 12 ++--- 7 files changed, 9 insertions(+), 146 deletions(-) delete mode 100644 src/core/device-idler.c delete mode 100644 src/core/device-idler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b26516..37e4111 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,6 @@ SET(VERSION 0.1.0) SET(SRCS src/apps/apps.c src/control/control.c - src/core/device-idler.c src/core/late-booting-done-notifier.c src/core/devices.c src/core/event-handler.c diff --git a/src/core/device-idler.c b/src/core/device-idler.c deleted file mode 100644 index 6275c3b..0000000 --- a/src/core/device-idler.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "log.h" - -struct device_request { - void (*func)(void *data); - void *data; -}; - -static GQueue req_queue = G_QUEUE_INIT; -static guint idler; - -static int free_request(struct device_request *req) -{ - if (!req) - return -EINVAL; - - free(req); - return 0; -} - -static gboolean idler_cb(void *data) -{ - struct device_request *req; - - req = g_queue_pop_head(&req_queue); - if (req) { - if (req->func) - req->func(req->data); - free_request(req); - } - - if (g_queue_is_empty(&req_queue)) { - idler = 0; - return G_SOURCE_REMOVE; - } - - return G_SOURCE_CONTINUE; -} - -static void process_next_request_in_idle(void) -{ - if (g_queue_is_empty(&req_queue)) - return; - - if (idler) - return; - - idler = g_idle_add(idler_cb, NULL); - /** - * if idler is null, - * it means whole system might be an abnormal state. - * so it just prints out error log. - */ - if (!idler) - _E("Failed to add request to idler."); -} - -int add_idle_request(void (*func)(void *data), void *data) -{ - struct device_request *req; - - if (!func) { - _E("Invalid argumet: func(NULL)"); - return -EINVAL; - } - - req = calloc(1, sizeof(struct device_request)); - if (!req) { - _E("Failed to allocate request: %d", errno); - return -errno; - } - - req->func = func; - req->data = data; - - g_queue_push_tail(&req_queue, req); - process_next_request_in_idle(); - - return 0; -} diff --git a/src/core/device-idler.h b/src/core/device-idler.h deleted file mode 100644 index 411e4bb..0000000 --- a/src/core/device-idler.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __DEVICE_IDLER_H__ -#define __DEVICE_IDLER_H__ - -/* - * To allow for callbacks to be called when the daemon is idle state. - */ - -int add_idle_request(void (*func)(void *data), void *data); - -#endif /* __DEVICE_IDLER_H__ */ diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 9503379..acf12d6 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -35,7 +35,6 @@ #include "lock-detector.h" #include "shared/common.h" #include "core/devices.h" -#include "core/device-idler.h" #include "shared/device-notifier.h" #include "apps/apps.h" #include "dd-display.h" @@ -1110,7 +1109,7 @@ static gboolean app_term(gpointer data) return G_SOURCE_REMOVE; } -static void expired_deliver_result(void *data) +static gboolean expired_deliver_result(gpointer data) { struct pmlock_expired_s *ex = data; struct pmlock_expired_s *item = NULL; @@ -1120,7 +1119,7 @@ static void expired_deliver_result(void *data) char *id; if (!ex) - return; + return G_SOURCE_REMOVE; len = strlen(ex->req_id) + 1; SYS_G_LIST_FOREACH(expired_req_list, l, item) { @@ -1154,6 +1153,8 @@ static void expired_deliver_result(void *data) out: free(ex); free(item); + + return G_SOURCE_REMOVE; } static GVariant *dbus_locktimeout_input(GDBusConnection *conn, @@ -1179,7 +1180,7 @@ static GVariant *dbus_locktimeout_input(GDBusConnection *conn, _I("req_id(%s), value(%d)", ex->req_id, ex->value); - add_idle_request(expired_deliver_result, ex); + g_idle_add(expired_deliver_result, (gpointer)ex); ret = 0; diff --git a/src/power/power-handler.c b/src/power/power-handler.c index df53032..2844825 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -40,7 +40,6 @@ #include "dd-deviced.h" #include "core/log.h" #include "shared/device-notifier.h" -#include "core/device-idler.h" #include "shared/common.h" #include "core/devices.h" #include "display/poll.h" diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 7c16e39..349cc9d 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -28,7 +28,6 @@ #include #include "core/log.h" -#include "core/device-idler.h" #include "shared/device-notifier.h" #include "core/devices.h" diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index def3ba6..7843e81 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -30,7 +30,6 @@ #include "core/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" -#include "core/device-idler.h" #include "apps/apps.h" #include "extcon/extcon.h" #include "display/display-ops.h" @@ -784,9 +783,11 @@ out: return ret; } -static void store_idler_cb(void *data) +static gboolean store_idler_cb(gpointer data) { store_policy(); + + return G_SOURCE_REMOVE; } static void destroy_open_request(struct usbhost_open_request *req) @@ -892,7 +893,6 @@ static void popup_result_signal_handler(GDBusConnection *conn, { int allow = 0, always = 0; - int ret; struct policy_entry *entry; int value; struct usbhost_open_request *req; @@ -972,11 +972,7 @@ static void popup_result_signal_handler(GDBusConnection *conn, entry->value = value; SYS_G_LIST_APPEND(access_list, entry); - ret = add_idle_request(store_idler_cb, NULL); - if (ret < 0) { - _E("Failed to add store idle request: %d", ret); - store_idler_cb(NULL); - } + g_idle_add(store_idler_cb, NULL); out: finish_opening(req, value); -- 2.7.4