Add defensive code for spurious wakeup 39/234039/1 accepted/tizen/unified/20200529.124406 submit/tizen/20200522.014428
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 21 May 2020 07:55:23 +0000 (16:55 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 21 May 2020 07:55:23 +0000 (16:55 +0900)
[Version] 0.3.20
[Profile] Common
[Issue Type] Improvement

Change-Id: I9ecc9e083c4197258a642965740a278ee30ac930
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/recorder_private.h
packaging/capi-media-recorder.spec
src/recorder.c

index 1c308e6..fe80627 100644 (file)
@@ -87,7 +87,7 @@ typedef struct _recorder_cb_info_s {
        gchar recv_msg[MUSE_MSG_MAX_LENGTH + 1];
        GCond api_cond[MUSE_RECORDER_API_MAX];
        GMutex api_mutex[MUSE_RECORDER_API_MAX];
-       gint api_activating[MUSE_RECORDER_API_MAX];
+       gboolean api_activating[MUSE_RECORDER_API_MAX];
        gint api_waiting[MUSE_RECORDER_API_MAX];
        gint api_ret[MUSE_RECORDER_API_MAX];
 
index f13809e..6a3b9f5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-recorder
 Summary:    A Recorder API
-Version:    0.3.19
+Version:    0.3.20
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 64534c8..1f315cd 100644 (file)
@@ -36,8 +36,8 @@
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
-#define LOG_TAG "TIZEN_N_RECORDER"
-#define MODULE_NAME "recorder"
+#define LOG_TAG         "TIZEN_N_RECORDER"
+#define MODULE_NAME     "recorder"
 
 /* for device changed callback */
 static GMutex g_rec_dev_state_changed_cb_lock;
@@ -791,7 +791,7 @@ static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg, int t
 
                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 {
@@ -860,9 +860,9 @@ static void *_recorder_msg_handler_func(gpointer data)
                        if (muse_recorder_msg_get(ret, rec_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("recorder api %d - return 0x%x", ret);*/
+                                       /*LOGD("recorder api %d - return 0x%x", api, ret);*/
 
                                        g_cond_signal(&cb_info->api_cond[api]);
                                } else {
@@ -1184,36 +1184,33 @@ static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder
 
        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 == RECORDER_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 = RECORDER_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 was TIMED OUT!", api);
+                       ret = RECORDER_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...");
        }
 
-       if (ret != RECORDER_ERROR_NONE)
-               LOGE("ERROR : api %d - ret 0x%x", api, ret);
+       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 != RECORDER_ERROR_NONE)
+               LOGE("ERROR : api %d - ret 0x%x", api, ret);
+
        return ret;
 }