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>
#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)
{
EXPORT int hal_power_get_backend(unsigned int res_type)
{
+ g_power_funcs_count++;
+
if (!g_power_funcs) {
int ret;
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;