resource: Initialize all resource drivers at start up 81/279981/2
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 19 Aug 2022 07:30:29 +0000 (16:30 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 22 Aug 2022 23:37:48 +0000 (08:37 +0900)
Instead of initalizing common or permanent data for resource drivers
at creation, now all initialization will be done at start up once.

Change-Id: Idf673d3997c3567b572bcc9ea6dae5e887a0d3f3
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
include/util/resource.h
src/monitor/monitor.c
src/util/resource.c

index d47db5a..19a08ab 100644 (file)
@@ -195,6 +195,9 @@ void init_resource_id(void);
 
 int set_resource_privdata(struct resource *resource, void *priv);
 
+void init_resource_drivers(void);
+void exit_resource_drivers(void);
+
 inline __attribute__((always_inline)) int64_t get_time_now(void)
 {
        struct timeval tv;
index 3e1787f..dd0e818 100644 (file)
@@ -34,6 +34,8 @@ static int monitor_setup(void *data, void *user_data)
 {
        int ret;
 
+       init_resource_drivers();
+
        ret = request_server_init();
        if (ret < 0) {
                _E("failed to initialize request server\n");
@@ -59,6 +61,7 @@ static void monitor_exit(void *data)
 {
        monitor_thread_exit(&g_monitor);
        request_server_exit();
+       exit_resource_drivers();
        unregister_notifier(DEVICE_NOTIFIER_INIT_DONE, monitor_setup, NULL);
 }
 
index 02e5ff9..3e7b828 100644 (file)
@@ -1138,3 +1138,34 @@ int set_resource_privdata(struct resource *resource, void *priv)
 
        return 0;
 }
+
+void init_resource_drivers(void)
+{
+       struct resource_driver *driver;
+       int i, ret = 0;
+
+       for (i = 0; i < g_list_length(g_resource_driver_head); i++) {
+               driver = g_list_nth(g_list_first(g_resource_driver_head), i)->data;
+
+               if (driver->ops.init) {
+                       ret = driver->ops.init();
+                       if (ret < 0) {
+                               _D("failed to init resource driver: %s\n", driver->name);
+                               remove_resource_driver(driver);
+                       }
+               }
+       }
+}
+
+void exit_resource_drivers(void)
+{
+       const struct resource_driver *driver;
+       int i;
+
+       for (i = 0; i < g_list_length(g_resource_driver_head); i++) {
+               driver = g_list_nth(g_list_first(g_resource_driver_head), i)->data;
+
+               if (driver->ops.exit)
+                       driver->ops.exit();
+       }
+}