From 8aaf0fefc8038d6c51649e07ef26c7726cecc2f7 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 16 Jun 2023 13:47:25 +0900 Subject: [PATCH] Fix "invalid signal received" error - If the same API is called in several threads simultaneously, "api_activating[api]" value is reset when first response is come. As a result, second response will get "invalid signal received" error. - This patch changes type of "api_activating" member variable from "gboolean" to "gint", and use it like reference count. [Version] 0.4.112 [Issue Type] Bug fix Change-Id: Ib98a2148e74e21e0b2d4d896b3b0f1baa4d0813b Signed-off-by: Jeongmo Yang --- include/camera_private.h | 2 +- packaging/capi-media-camera.spec | 2 +- src/camera.c | 42 +++++++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/include/camera_private.h b/include/camera_private.h index a5b9156..9e5a180 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -157,7 +157,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]; - gboolean api_activating[MUSE_CAMERA_API_MAX]; + gint 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 1ec8a93..6ac8a90 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.111 +Version: 0.4.112 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index c5494f5..c5b61c2 100644 --- a/src/camera.c +++ b/src/camera.c @@ -899,16 +899,17 @@ int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *c g_mutex_lock(&(cb_info->api_mutex[api])); - CAM_LOG_INFO("api [%d], timeout [%d sec]", api, time_out); + CAM_LOG_INFO("api[%d] timeout[%ds] START:activating[%d]", + api, time_out, cb_info->api_activating[api]); end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND; - while (!cb_info->api_activating[api]) { + while (cb_info->api_activating[api] <= 0) { if (time_out == CAMERA_CB_NO_TIMEOUT) { g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api])); - CAM_LOG_WARNING("api %d returned 0x%x", api, cb_info->api_ret[api]); + CAM_LOG_WARNING("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)) { - CAM_LOG_ERROR("api %d TIMED OUT!", api); + CAM_LOG_ERROR("api[%d] TIMED OUT!", api); ret = CAMERA_ERROR_INVALID_OPERATION; goto _CB_RETURN_END; } @@ -918,12 +919,19 @@ int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *c goto _CB_RETURN_END; } - if (!cb_info->api_activating[api]) - CAM_LOG_WARNING("invalid signal received, wait again..."); + if (cb_info->api_activating[api] <= 0) + CAM_LOG_WARNING("api[%d] invalid signal received, wait again...", api); } ret = cb_info->api_ret[api]; - cb_info->api_activating[api] = FALSE; + + if (cb_info->api_activating[api] > 0) { + cb_info->api_activating[api]--; + CAM_LOG_INFO("api[%d] END:activating[%d]", api, cb_info->api_activating[api]); + } else { + CAM_LOG_WARNING("api[%d] invalid activating[%d]", + api, cb_info->api_activating[api]); + } _CB_RETURN_END: g_mutex_unlock(&(cb_info->api_mutex[api])); @@ -1812,7 +1820,15 @@ 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] = TRUE; + + if (cb_info->api_activating[api] < 0) { + CAM_LOG_WARNING("api[%d] invalid activating[%d]", + api, cb_info->api_activating[api]); + + cb_info->api_activating[api] = 0; + } + + cb_info->api_activating[api]++; CAM_LOG_DEBUG("t[%d] camera api[%d] - return[0x%x]", type, api, ret); @@ -2124,7 +2140,15 @@ 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] = TRUE; + + if (cb_info->api_activating[api] < 0) { + CAM_LOG_WARNING("api[%d] invalid activating[%d]", + api, cb_info->api_activating[api]); + + cb_info->api_activating[api] = 0; + } + + cb_info->api_activating[api]++; g_cond_broadcast(&cb_info->api_cond[api]); } else { -- 2.7.4