static int g_rec_dev_state_changed_cb_id;
static GDBusConnection *g_rec_dev_state_changed_cb_conn;
static guint g_rec_dev_state_changed_cb_subscribe_id;
+static GMutex g_rec_idle_event_lock;
}
-static bool _recorder_idle_event_callback(void *data)
+static gboolean _recorder_idle_event_callback(gpointer data)
{
recorder_cb_info_s *cb_info = NULL;
recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
if (rec_idle_event == NULL) {
LOGE("rec_idle_event is NULL");
- return false;
+ return FALSE;
}
/* lock event */
- g_mutex_lock(&rec_idle_event->event_mutex);
+ g_mutex_lock(&g_rec_idle_event_lock);
cb_info = rec_idle_event->cb_info;
if (cb_info == NULL) {
LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
+ g_mutex_unlock(&g_rec_idle_event_lock);
goto IDLE_EVENT_CALLBACK_DONE;
}
/* remove event from list */
- g_mutex_lock(&cb_info->idle_event_mutex);
-
if (cb_info->idle_event_list)
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
- /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_rec_idle_event_lock);
/* user callback */
_recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
- /* send signal for waiting thread */
- g_cond_signal(&cb_info->idle_event_cond);
-
IDLE_EVENT_CALLBACK_DONE:
- /* unlock and release event */
- g_mutex_unlock(&rec_idle_event->event_mutex);
- g_mutex_clear(&rec_idle_event->event_mutex);
-
+ /* release event */
g_free(rec_idle_event);
rec_idle_event = NULL;
- return false;
+ return FALSE;
}
{
recorder_idle_event_s *rec_idle_event = NULL;
GList *list = NULL;
- gint64 end_time = 0;
if (cb_info == NULL) {
LOGE("cb_info is NULL");
return;
}
- g_mutex_lock(&cb_info->idle_event_mutex);
+ g_mutex_lock(&g_rec_idle_event_lock);
if (cb_info->idle_event_list == NULL) {
LOGD("No event");
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
- g_mutex_clear(&rec_idle_event->event_mutex);
g_free(rec_idle_event);
rec_idle_event = NULL;
continue;
}
- LOGW("remove idle event %p failed", rec_idle_event);
-
- if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
- LOGW("lock failed, %p event is calling now", rec_idle_event);
-
- end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
-
- if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
- LOGW("signal received");
- else
- LOGW("timeout");
-
- continue;
- }
-
LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
rec_idle_event, rec_idle_event->event);
rec_idle_event->cb_info = NULL;
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
-
- g_mutex_unlock(&rec_idle_event->event_mutex);
}
g_list_free(cb_info->idle_event_list);
cb_info->idle_event_list = NULL;
}
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_rec_idle_event_lock);
return;
}
rec_idle_event->event = rec_msg->event;
rec_idle_event->cb_info = cb_info;
- g_mutex_init(&rec_idle_event->event_mutex);
+
strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
/*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
- g_mutex_lock(&cb_info->idle_event_mutex);
+ g_mutex_lock(&g_rec_idle_event_lock);
cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_rec_idle_event_lock);
g_idle_add_full(G_PRIORITY_DEFAULT,
(GSourceFunc)_recorder_idle_event_callback,
g_cond_init(&cb_info->api_cond[i]);
}
- g_mutex_init(&cb_info->idle_event_mutex);
- g_cond_init(&cb_info->idle_event_cond);
-
for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
g_mutex_init(&cb_info->user_cb_mutex[i]);
for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
g_mutex_clear(&cb_info->user_cb_mutex[i]);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
-
for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
g_mutex_clear(&cb_info->api_mutex[i]);
g_cond_clear(&cb_info->api_cond[i]);
for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
g_mutex_clear(&cb_info->user_cb_mutex[i]);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
-
for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
g_mutex_clear(&cb_info->api_mutex[i]);
g_cond_clear(&cb_info->api_cond[i]);