From 7941cfbc65a4abcdc1e9c45716e0561348b0ed2a Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 8 Mar 2018 21:35:07 +0900 Subject: [PATCH] thread: checking waiting cb_type if waiting_cb_type != cb_type->type, send cb to other thread if needed. when a thread is waiting status, if other thread tries to send the same type cb as sync, we CAN'T handle it. So we'd better make assert it to find another solution. Change-Id: I06f92b2814a3a4e0d23d9d6df3c8b17526e1175f --- src/tdm_thread.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tdm_thread.c b/src/tdm_thread.c index db910c2..ca59103 100644 --- a/src/tdm_thread.c +++ b/src/tdm_thread.c @@ -613,6 +613,7 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) struct list_head *list, *other_list; struct list_head call_list; static pid_t waiting_tid = 0; + static tdm_thread_cb_type waiting_cb_type = TDM_THREAD_CB_NONE; tdm_error ret; TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED); @@ -626,6 +627,10 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) assert(find_funcs[cb_base->type] != NULL); + /* When there is the previous waiting sync call, the other type sync call CAN't be handlered */ + if (waiting_tid > 0 && cb_base->sync == 1) + assert(waiting_cb_type == cb_base->type); + if (!object) { object = find_funcs[cb_base->type](private_display, cb_base->object_stamp); if (!object) { @@ -670,7 +675,7 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) assert(LIST_IS_EMPTY(&call_list)); - if (waiting_tid == 0) { + if (waiting_tid == 0 || waiting_cb_type != cb_base->type) { LIST_FOR_EACH_ENTRY_SAFE(cb, hh, other_list, link) { if (cb->object != object || cb->cb_type != cb_base->type || @@ -686,6 +691,7 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) if (keep_private_thread) { if (cb_base->sync) { waiting_tid = 0; + waiting_cb_type = TDM_THREAD_CB_NONE; pthread_cond_signal(&keep_private_thread->event_cond); if (tdm_debug_module & TDM_DEBUG_THREAD) TDM_INFO("pthread broadcase"); @@ -712,6 +718,8 @@ tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base) */ tdm_mutex_locked = 0; waiting_tid = caller_tid; + waiting_cb_type = cb_base->type; + pthread_cond_wait(&keep_private_thread->event_cond, &private_display->lock); tdm_mutex_locked = 1; } -- 2.7.4