[0.3.104] return pending api before destroy the resources 36/191636/3 accepted/tizen/unified/20181113.163418 submit/tizen/20181109.060212
authorEunhae Choi <eunhae1.choi@samsung.com>
Fri, 19 Oct 2018 09:36:23 +0000 (18:36 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 19 Oct 2018 10:36:11 +0000 (19:36 +0900)
- csharp app can call the destroy during prepare
  because it works different thread.
- player have to send cond signal of each api
  to make sure return the pending api before destroy the cb info resource.

Change-Id: Ide173b6f1d3f0c896ad4b6f3cbd01346af90a77e

packaging/capi-media-player.spec
src/player.c

index 8e4c4c31c6eb21379b37d7cddb15e1f25360d229..2bd8835be05ad85da5274e1d09695a7d08f5843e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    0.3.103
+Version:    0.3.104
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 2956c5b1487ba93eadae17bd16110894d7dd2f02..f38da0e9c2eec5fbbe171f36ea3b5c5ce9c66eef 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sched.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <syscall.h>
@@ -1713,6 +1714,8 @@ static void *client_cb_handler(gpointer data)
        }
        if (g_atomic_int_get(&cb_info->running))
                _notify_disconnected(cb_info);
+
+       g_atomic_int_set(&cb_info->running, 0);
        LOGD("client cb exit");
 
        return NULL;
@@ -1771,9 +1774,19 @@ static void callback_destroy(callback_cb_info_s * cb_info)
 
        LOGI("%p Callback destroyed", cb_info);
 
-       g_mutex_clear(&cb_info->player_mutex);
-       for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
+       for (i = 0; i < MUSE_PLAYER_API_MAX; i++) {
+               g_mutex_lock(&cb_info->player_mutex);
+               g_cond_signal(&cb_info->player_cond[i]);
+               g_mutex_unlock(&cb_info->player_mutex);
                g_cond_clear(&cb_info->player_cond[i]);
+       }
+
+       /* to make sure the return of other pending api */
+       sched_yield();
+       g_mutex_lock(&cb_info->player_mutex);
+       g_mutex_unlock(&cb_info->player_mutex);
+       g_mutex_clear(&cb_info->player_mutex);
+
        g_cond_clear(&cb_info->server_ack_cond);
 
        g_mutex_clear(&cb_info->data_mutex);
@@ -1827,6 +1840,7 @@ int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_inf
                                break;
                        }
                }
+
                if (!msg)
                        msg = _get_ret_msg(api, cb_info);
                if (msg) {
@@ -1837,11 +1851,17 @@ int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_inf
                                ret = PLAYER_ERROR_INVALID_OPERATION;
                        else if (ret != PLAYER_ERROR_NONE)
                                LOGE("Get error return from server 0x%X", ret);
+                       break;
+               }
 
+               if (!g_atomic_int_get(&cb_info->running)) {
+                       LOGE("callback thread is stopped. %d api did not get return in time", api);
+                       ret = PLAYER_ERROR_INVALID_OPERATION;
+                       break;
                } else {
-                       LOGE("api %d is the spurious wakeup", api);
+                       LOGW("api %d is the spurious wakeup, wait again", api);
                }
-       } while (!msg);
+       } while (!msg && g_atomic_int_get(&cb_info->running));
 
        g_mutex_unlock(&cb_info->player_mutex);
        return ret;