hal-api: power: Use usage_count to support multiple call accepted/tizen/6.5/unified/20211028.115016 accepted/tizen/unified/20210929.022354 submit/tizen/20210928.093203 submit/tizen_6.5/20211028.163201 tizen_6.5.m2_release
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 28 Sep 2021 07:20:40 +0000 (16:20 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 28 Sep 2021 09:31:32 +0000 (18:31 +0900)
The user of hal-api-power such as PASS daemon can execute
the hal_power_get_backend and hal_power_put_backend at multiple times.

Until now, hal-api-power doesn't support the multiple function call
of hal_power_get_backend/put_backend. It cause that return error value
when calling hal_power_put_backend from user of hal-api-power.

In order to fix this issue, use usage_count to put the hal backend
when usage_count is zero.

Change-Id: Idc1aef66e09e335cc158ace4c359673ff45792b8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/hal-api-power.c

index e103ff9..61a3e09 100644 (file)
@@ -32,6 +32,7 @@
 #define ARRAY_SIZE(name)       (sizeof(name)/sizeof(name[0]))
 
 static hal_backend_power_funcs *g_power_funcs = NULL;
+static unsigned int g_power_funcs_count = 0;
 
 static int is_supported_from_backend(hal_backend_power_funcs *funcs, int res_type)
 {
@@ -155,6 +156,8 @@ static struct pass_resource_battery_ops *get_charging(hal_backend_power_funcs *f
 
 EXPORT int hal_power_get_backend(unsigned int res_type)
 {
+       g_power_funcs_count++;
+
        if (!g_power_funcs) {
                int ret;
 
@@ -177,8 +180,11 @@ EXPORT int hal_power_get_backend(unsigned int res_type)
 
 EXPORT int hal_power_put_backend(void)
 {
-       if (!g_power_funcs)
-               return -ENOTSUP;
+       if (!g_power_funcs_count)
+               return 0;
+
+       if (--g_power_funcs_count > 0)
+               return 0;
 
        hal_common_put_backend(HAL_MODULE_POWER, (void *)g_power_funcs);
        g_power_funcs = NULL;