From 20a81eedd3756b10a5190b0c158aac753f8dc32e Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 26 Feb 2018 15:38:41 +0900 Subject: [PATCH] thread: fix deadlock issue when there are callbacks in cb_list[0] and cb_list[1], display-thread and tdm- thread are slept in pthread_cond_wait. Change-Id: If5d459b5f8579fcbf05765de12f76cca548de6eb --- src/tdm_thread.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tdm_thread.c b/src/tdm_thread.c index 3811bdc..38a76a4 100644 --- a/src/tdm_thread.c +++ b/src/tdm_thread.c @@ -610,6 +610,7 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) pid_t caller_tid; struct list_head *list, *other_list; struct list_head call_list; + static pid_t waiting_tid = 0; tdm_error ret; TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED); @@ -667,19 +668,22 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) assert(LIST_IS_EMPTY(&call_list)); - LIST_FOR_EACH_ENTRY_SAFE(cb, hh, other_list, link) { - if (cb->object != object || - cb->cb_type != cb_base->type || - cb->cb_data != cb_base->data) - continue; + if (waiting_tid == 0) { + LIST_FOR_EACH_ENTRY_SAFE(cb, hh, other_list, link) { + if (cb->object != object || + cb->cb_type != cb_base->type || + cb->cb_data != cb_base->data) + continue; - handler_in_other_thread = 1; - break; + handler_in_other_thread = 1; + break; + } } if (!handler_in_other_thread) { if (keep_private_thread) { if (cb_base->sync) { + waiting_tid = 0; pthread_cond_signal(&keep_private_thread->event_cond); if (tdm_debug_module & TDM_DEBUG_THREAD) TDM_INFO("pthread broadcase"); @@ -705,6 +709,7 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) * the mutex shall have been locked and shall be owned by the calling thread */ tdm_mutex_locked = 0; + waiting_tid = caller_tid; pthread_cond_wait(&keep_private_thread->event_cond, &private_display->lock); tdm_mutex_locked = 1; } -- 2.7.4