From: Unsung Lee Date: Fri, 5 Aug 2022 06:57:41 +0000 (+0900) Subject: Move dlopen and dlsym to the constructor X-Git-Tag: submit/tizen/20220805.071952^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96f60bd7bb249460e6faddec87ab5dfe469c63b1;p=platform%2Fcore%2Fapi%2Fresource.git Move dlopen and dlsym to the constructor Change-Id: I33b8185e5449bd224051e009a9130097bd3662bf Signed-off-by: Unsung Lee --- diff --git a/src/cpu-boosting.c b/src/cpu-boosting.c index daf5826..56ba7f4 100644 --- a/src/cpu-boosting.c +++ b/src/cpu-boosting.c @@ -27,27 +27,45 @@ #include "common.h" static void *plugin_handle = NULL; +int (*plugin_resource_set_cpu_boosting)(resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flags, int timeout_msec) = NULL; +int (*plugin_resource_clear_cpu_boosting)(resource_pid_t pid) = NULL; +int (*plugin_resource_get_cpu_boosting_level)(resource_pid_t pid, cpu_boosting_level_info_t *level) = NULL; +int (*plugin_resource_set_cpu_inheritance)(pid_t source_tid, const char *dest_process, int timeout_msec) = NULL; +int (*plugin_resource_clear_cpu_inheritance)(pid_t source_tid, const char *dest_process) = NULL; +int (*plugin_resource_register_cpu_inheritance_destination)(const char *dest_process, resource_pid_t pid) = NULL; +int (*plugin_resource_unregister_cpu_inheritance_destination)(const char *dest_process) = NULL; #define CPU_BOOSTING_PLUGIN_PATH PLUGIN_PATH"/libcapi-system-resource-plugin.so" static int open_cpu_boosting_plugin(void) { - if (plugin_handle) - return RESOURCE_ERROR_NONE; - if (access(CPU_BOOSTING_PLUGIN_PATH, F_OK) != 0) { _E("[CPU-BOOSTING] Cannot find a plugin file"); return RESOURCE_ERROR_NO_SUCH_FILE; } - else { - plugin_handle = dlopen(CPU_BOOSTING_PLUGIN_PATH, RTLD_NOW); - if (!plugin_handle) { - _E("[CPU-BOOSTING] Failed to load %s", CPU_BOOSTING_PLUGIN_PATH); - return RESOURCE_ERROR_NOT_SUPPORTED; - } - - return RESOURCE_ERROR_NONE; + + plugin_handle = dlopen(CPU_BOOSTING_PLUGIN_PATH, RTLD_NOW); + if (!plugin_handle) { + _E("[CPU-BOOSTING] Failed to load %s", CPU_BOOSTING_PLUGIN_PATH); + return RESOURCE_ERROR_NOT_SUPPORTED; } + + plugin_resource_set_cpu_boosting = + dlsym(plugin_handle, "resource_set_cpu_boosting"); + plugin_resource_clear_cpu_boosting = + dlsym(plugin_handle, "resource_clear_cpu_boosting"); + plugin_resource_get_cpu_boosting_level = + dlsym(plugin_handle, "resource_get_cpu_boosting_level"); + plugin_resource_set_cpu_inheritance = + dlsym(plugin_handle, "resource_set_cpu_inheritance"); + plugin_resource_clear_cpu_inheritance = + dlsym(plugin_handle, "resource_clear_cpu_inheritance"); + plugin_resource_register_cpu_inheritance_destination = + dlsym(plugin_handle, "resource_register_cpu_inheritance_destination"); + plugin_resource_unregister_cpu_inheritance_destination = + dlsym(plugin_handle, "resource_unregister_cpu_inheritance_destination"); + + return RESOURCE_ERROR_NONE; } API int resource_set_cpu_boosting (resource_pid_t pid, @@ -56,13 +74,8 @@ API int resource_set_cpu_boosting (resource_pid_t pid, int ret; int (*func)(resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flags, int timeout_msec) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_set_cpu_boosting"); + func = plugin_resource_set_cpu_boosting; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -80,13 +93,8 @@ API int resource_clear_cpu_boosting (resource_pid_t pid) int ret; int (*func)(resource_pid_t pid) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_clear_cpu_boosting"); + func = plugin_resource_clear_cpu_boosting; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -105,13 +113,8 @@ API int resource_get_cpu_boosting_level (resource_pid_t pid, int ret; int (*func)(resource_pid_t pid, cpu_boosting_level_info_t *level) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_get_cpu_boosting_level"); + func = plugin_resource_get_cpu_boosting_level; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -129,13 +132,8 @@ API int resource_set_cpu_inheritance (pid_t source_tid, const char *dest_process int ret; int (*func)(pid_t source_tid, const char *dest_process, int timeout_msec) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_set_cpu_inheritance"); + func = plugin_resource_set_cpu_inheritance; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -153,13 +151,8 @@ API int resource_clear_cpu_inheritance (pid_t source_tid, const char *dest_proce int ret; int (*func)(pid_t source_tid, const char *dest_process) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_clear_cpu_inheritance"); + func = plugin_resource_clear_cpu_inheritance; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -177,13 +170,8 @@ API int resource_register_cpu_inheritance_destination (const char *dest_process, int ret; int (*func)(const char *dest_process, resource_pid_t pid) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_register_cpu_inheritance_destination"); + func = plugin_resource_register_cpu_inheritance_destination; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -201,13 +189,8 @@ API int resource_unregister_cpu_inheritance_destination (const char *dest_proces int ret; int (*func)(const char *dest_process) = NULL; - ret = open_cpu_boosting_plugin(); - if (ret != RESOURCE_ERROR_NONE) - return ret; - - func = dlsym(plugin_handle, "resource_unregister_cpu_inheritance_destination"); + func = plugin_resource_unregister_cpu_inheritance_destination; if (!func) { - _E("[CPU-BOOSTING] dlsym failed: %s", dlerror()); return RESOURCE_ERROR_NOT_SUPPORTED; } @@ -222,6 +205,7 @@ API int resource_unregister_cpu_inheritance_destination (const char *dest_proces static void __CONSTRUCTOR__ cpu_boosting_init(void) { + open_cpu_boosting_plugin(); } static void __DESTRUCTOR__ cpu_boosting_exit(void)