From 5d6f7f9ed41adb433e2fcf5e4ee874197b02f0e1 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 16 Mar 2020 17:58:02 +0900 Subject: [PATCH] Add defensive code for spurious wakeup [Version] 0.4.30 [Profile] Common [Issue Type] Update Change-Id: I82b52f1d3ea0ab4c9b0ab6f3cbfc1934b21bf3c2 Signed-off-by: Jeongmo Yang --- include/camera_private.h | 2 +- packaging/capi-media-camera.spec | 2 +- src/camera.c | 47 ++++++++++++++++++---------------------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/include/camera_private.h b/include/camera_private.h index 0ce8ed9..0b79381 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -125,7 +125,7 @@ typedef struct _camera_cb_info_s { gchar recv_msg[MUSE_MSG_MAX_LENGTH + 1]; GCond api_cond[MUSE_CAMERA_API_MAX]; GMutex api_mutex[MUSE_CAMERA_API_MAX]; - gint api_activating[MUSE_CAMERA_API_MAX]; + gboolean api_activating[MUSE_CAMERA_API_MAX]; gint api_waiting[MUSE_CAMERA_API_MAX]; gint api_ret[MUSE_CAMERA_API_MAX]; diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index ddefff8..f882d77 100644 --- a/packaging/capi-media-camera.spec +++ b/packaging/capi-media-camera.spec @@ -1,6 +1,6 @@ Name: capi-media-camera Summary: A Camera API -Version: 0.4.29 +Version: 0.4.30 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index 9aa8b48..4ffe014 100644 --- a/src/camera.c +++ b/src/camera.c @@ -33,8 +33,8 @@ #ifdef LOG_TAG #undef LOG_TAG #endif -#define LOG_TAG "TIZEN_N_CAMERA" -#define MODULE_NAME "camera" +#define LOG_TAG "TIZEN_N_CAMERA" +#define MODULE_NAME "camera" /* for device changed callback */ static GMutex g_cam_dev_state_changed_cb_lock; @@ -637,8 +637,6 @@ static int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_in int ret = CAMERA_ERROR_NONE; gint64 end_time; - /*LOGD("Enter api : %d", api);*/ - if (!cb_info->is_server_connected) { LOGE("server is disconnected"); return CAMERA_ERROR_SERVICE_DISCONNECTED; @@ -646,31 +644,28 @@ static int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_in g_mutex_lock(&(cb_info->api_mutex[api])); - if (cb_info->api_activating[api] == 0) { + LOGD("api [%d], timeout [%d sec]", api, time_out); + + end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND; + + while (!cb_info->api_activating[api]) { if (time_out == CAMERA_CB_NO_TIMEOUT) { - LOGW("wait for api %d", api); g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api])); - ret = cb_info->api_ret[api]; - cb_info->api_activating[api] = 0; - LOGW("api %d returned 0x%x", api, ret); - } else { - end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND; - if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) { - ret = cb_info->api_ret[api]; - cb_info->api_activating[api] = 0; - /*LOGD("return value : 0x%x", ret);*/ - } else { - ret = CAMERA_ERROR_INVALID_OPERATION; - LOGE("api %d was TIMED OUT!", api); - } + LOGW("api %d returned 0x%x", api, cb_info->api_ret[api]); + } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) { + LOGE("api %d TIMED OUT!", api); + ret = CAMERA_ERROR_INVALID_OPERATION; + goto _CB_RETURN_END; } - } else { - ret = cb_info->api_ret[api]; - cb_info->api_activating[api] = 0; - /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/ + if (!cb_info->api_activating[api]) + LOGW("invalid signal received, wait again..."); } + ret = cb_info->api_ret[api]; + cb_info->api_activating[api] = FALSE; + +_CB_RETURN_END: g_mutex_unlock(&(cb_info->api_mutex[api])); if (ret != CAMERA_ERROR_NONE) @@ -1737,9 +1732,9 @@ static gpointer _camera_msg_handler_func(gpointer data) if (muse_camera_msg_get(ret, cam_msg->recv_msg)) { if (cb_info->api_waiting[api] > 0) { cb_info->api_ret[api] = ret; - cb_info->api_activating[api] = 1; + cb_info->api_activating[api] = TRUE; - /*LOGD("t:%d camera api %d - return 0x%x", type, ret);*/ + /*LOGD("t:%d camera api %d - return 0x%x", type, api, ret);*/ g_cond_signal(&cb_info->api_cond[api]); } else { @@ -2023,7 +2018,7 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd) if (cb_info->api_waiting[api] > 0) { cb_info->api_ret[api] = ret; - cb_info->api_activating[api] = 1; + cb_info->api_activating[api] = TRUE; g_cond_signal(&cb_info->api_cond[api]); } else { -- 2.7.4