Re-wait at the spurious wakeup of g_cond_wait_until 95/105895/1
authorHyongtaek Lim <hyongtaek.lim@samsung.com>
Thu, 1 Dec 2016 09:33:18 +0000 (18:33 +0900)
committereunhae choi <eunhae1.choi@samsung.com>
Tue, 20 Dec 2016 03:30:28 +0000 (19:30 -0800)
Change-Id: Idb14c155c6adf9da5b2a925b00ef165dc71b8c5a
Signed-off-by: Hyongtaek Lim <hyongtaek.lim@samsung.com>
(cherry picked from commit deb470b7f19551053e4b9fbd2d345c3425aefa54)

src/player.c

index 42f3d59..701176c 100644 (file)
@@ -1390,6 +1390,20 @@ static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_in
        return NULL;
 }
 
+static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
+{
+       ret_msg_s *msg = cb_info->buff.retMsgHead;
+       ret_msg_s *prev = NULL;
+       while (msg) {
+               prev = msg;
+               msg = msg->next;
+               LOGI("Remove %s", prev->msg);
+               g_free(prev->msg);
+               prev->msg = NULL;
+               g_free(prev);
+       }
+}
+
 static void _notify_disconnected(callback_cb_info_s * cb_info)
 {
        int code = PLAYER_ERROR_SERVICE_DISCONNECTED;
@@ -1551,6 +1565,7 @@ static void callback_destroy(callback_cb_info_s * cb_info)
        g_mutex_clear(&cb_info->seek_cb_mutex);
 
        g_free(cb_info->buff.recvMsg);
+       _remove_all_ret_msg(cb_info);
        if (cb_info->buff.part_of_msg)
                g_free(cb_info->buff.part_of_msg);
        g_free(cb_info);
@@ -1589,28 +1604,28 @@ int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_inf
        g_mutex_lock(&cb_info->player_mutex);
 
        msg = _get_ret_msg(api, cb_info);
-       if (!buff->recved || !msg) {
-               if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
-                       LOGW("api %d return msg does not received %dms", api, time_out);
-                       g_mutex_unlock(&cb_info->player_mutex);
-                       return PLAYER_ERROR_INVALID_OPERATION;
+       do {
+               if (!buff->recved || !msg) {
+                       if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
+                               LOGW("api %d return msg does not received %dms", api, time_out);
+                               ret = PLAYER_ERROR_INVALID_OPERATION;
+                               break;
+                       }
                }
-       }
-       if (!msg)
-               msg = _get_ret_msg(api, cb_info);
-       if (msg) {
-               *ret_buf = msg->msg;
-               g_free(msg);
-               if (!player_msg_get(ret, *ret_buf))
-                       ret = PLAYER_ERROR_INVALID_OPERATION;
-       } else {
-               LOGE("api %d return msg is not exist", api);
-               ret = PLAYER_ERROR_INVALID_OPERATION;
-       }
-       buff->recved--;
+               if (!msg)
+                       msg = _get_ret_msg(api, cb_info);
+               if (msg) {
+                       *ret_buf = msg->msg;
+                       buff->recved--;
+                       g_free(msg);
+                       if (!player_msg_get(ret, *ret_buf))
+                               ret = PLAYER_ERROR_INVALID_OPERATION;
+               } else {
+                       LOGE("api %d is the spurious wakeup", api);
+               }
+       } while (!msg);
 
        g_mutex_unlock(&cb_info->player_mutex);
-
        return ret;
 }