#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syscall.h>
}
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;
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);
break;
}
}
+
if (!msg)
msg = _get_ret_msg(api, cb_info);
if (msg) {
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;