thread: fix deadlock issue 64/171064/2
authorBoram Park <boram1288.park@samsung.com>
Mon, 26 Feb 2018 06:38:41 +0000 (15:38 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 26 Feb 2018 23:50:59 +0000 (08:50 +0900)
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

index 3811bdc..38a76a4 100644 (file)
@@ -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;
        }