1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
40 #include "tdm_private.h"
42 static tdm_private_thread *keep_private_thread;
44 struct _tdm_private_thread {
45 tdm_private_loop *private_loop;
47 pthread_cond_t event_cond;
48 pthread_t event_thread;
53 /* 0: read, 1: write (tdm-thread -> display-thread) */
56 /* 0: read, 1: write (tdm-thread <- display-thread) */
58 tdm_event_loop_source *sub_event_source;
61 typedef struct _tdm_private_thread_cb {
62 struct list_head link;
63 struct list_head call_link;
66 tdm_thread_cb_type cb_type;
72 } tdm_private_thread_cb;
74 static tdm_thread_find_object find_funcs[TDM_THREAD_CB_MAX] = {0, };
76 /* 0: for display thread, 1: for tdm thread */
77 static struct list_head cb_list[2];
78 static pthread_mutex_t cb_list_lock;
80 static void _tdm_thread_free_cb(tdm_private_thread_cb *cb);
83 _tdm_thread_handle_events(int fd, tdm_event_loop_mask mask, void *user_data)
85 tdm_private_loop *private_loop = user_data;
88 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
89 TDM_RETURN_VAL_IF_FAIL(private_loop != NULL, TDM_ERROR_OPERATION_FAILED);
90 TDM_RETURN_VAL_IF_FAIL(private_loop->dpy != NULL, TDM_ERROR_OPERATION_FAILED);
92 ret = tdm_thread_handle_cb(private_loop);
94 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
96 return TDM_ERROR_NONE;
100 _tdm_thread_main(void *data)
102 tdm_private_thread *private_thread = (tdm_private_thread*)data;
103 tdm_private_loop *private_loop = private_thread->private_loop;
109 /* Not lock/unlock for the private_thread and private_loop structure
110 * because they won't be destroyed as long as tdm thread is running.
111 * When they're destroyed, we have already exit the tdm thread.
113 private_thread->thread_tid = syscall(SYS_gettid);
115 TDM_INFO("display_tid:%d, thread_tid: %d",
116 private_thread->display_tid, private_thread->thread_tid);
118 /* fd SHOULD be the same with sub_pipe[0] to make sure that using
119 * tdm_thread_get_fd, tdm_thread_send_cb, tdm_thread_handle_cb in
120 * both threads is fine. Otherwise, assert.
122 tdm_display_lock(private_loop->dpy);
123 assert(tdm_thread_get_fd(private_loop) == private_thread->sub_pipe[0]);
125 private_thread->sub_event_source =
126 tdm_event_loop_add_fd_handler(private_loop->dpy,
127 private_thread->sub_pipe[0],
128 TDM_EVENT_LOOP_READABLE,
129 _tdm_thread_handle_events,
132 TDM_GOTO_IF_FAIL(error == TDM_ERROR_NONE, exit_thread);
133 TDM_GOTO_IF_FAIL(private_thread->sub_event_source != NULL, exit_thread);
135 pthread_cond_signal(&private_thread->event_cond);
137 /* mutex shall be locked by the thread calling pthread_cond_signal() */
138 tdm_display_unlock(private_loop->dpy);
140 fd = tdm_event_loop_get_fd(private_loop->dpy);
142 TDM_ERR("couldn't get fd");
151 if (tdm_debug_module & TDM_DEBUG_EVENT)
152 TDM_INFO("server flush");
153 tdm_event_loop_flush(private_loop->dpy);
155 if (tdm_debug_module & TDM_DEBUG_EVENT)
156 TDM_INFO("fd(%d) polling in", fd);
158 ret = poll(&fds, 1, -1);
160 if (tdm_debug_module & TDM_DEBUG_EVENT)
161 TDM_INFO("fd(%d) polling out", fd);
164 if (errno == EINTR || errno == EAGAIN) /* normal case */
167 TDM_ERR("poll failed: %m");
172 if (tdm_debug_module & TDM_DEBUG_EVENT)
173 TDM_INFO("thread got events");
175 if (tdm_event_loop_dispatch(private_loop->dpy) < 0)
176 TDM_ERR("dispatch error");
180 tdm_display_unlock(private_loop->dpy);
184 /* NOTE: tdm thread doesn't care about multi-thread. */
186 tdm_thread_init(tdm_private_loop *private_loop)
188 tdm_private_display *private_display;
189 tdm_private_thread *private_thread;
192 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
193 TDM_RETURN_VAL_IF_FAIL(private_loop->dpy, TDM_ERROR_OPERATION_FAILED);
195 private_display = private_loop->dpy;
196 TDM_RETURN_VAL_IF_FAIL(private_display->private_loop, TDM_ERROR_OPERATION_FAILED);
198 if (private_loop->private_thread)
199 return TDM_ERROR_NONE;
201 for (i = 0; i < TDM_THREAD_CB_MAX; i++)
202 find_funcs[i] = NULL;
204 if (pthread_mutex_init(&cb_list_lock, NULL)) {
205 TDM_ERR("mutex init failed: %m");
206 return TDM_ERROR_OUT_OF_MEMORY;
209 LIST_INITHEAD(&cb_list[0]);
210 LIST_INITHEAD(&cb_list[1]);
212 /* enable as default */
213 thread = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1);
215 TDM_INFO("not using a TDM event thread");
216 return TDM_ERROR_NONE;
219 private_thread = calloc(1, sizeof * private_thread);
220 if (!private_thread) {
221 TDM_ERR("alloc failed");
222 return TDM_ERROR_OUT_OF_MEMORY;
225 if (pthread_cond_init(&private_thread->event_cond, NULL)) {
226 TDM_ERR("pthread_cond_init failed: %m");
227 free(private_thread);
228 return TDM_ERROR_OUT_OF_MEMORY;
231 if (pipe(private_thread->pipe) != 0) {
232 TDM_ERR("pipe failed: %m");
233 pthread_cond_destroy(&private_thread->event_cond);
234 free(private_thread);
235 return TDM_ERROR_OPERATION_FAILED;
238 if (pipe(private_thread->sub_pipe) != 0) {
239 TDM_ERR("sub_pipe failed: %m");
240 close(private_thread->pipe[0]);
241 close(private_thread->pipe[1]);
242 pthread_cond_destroy(&private_thread->event_cond);
243 free(private_thread);
244 return TDM_ERROR_OPERATION_FAILED;
247 keep_private_thread = private_thread;
249 private_thread->private_loop = private_loop;
250 private_loop->private_thread = private_thread;
252 private_thread->display_tid = syscall(SYS_gettid);
254 /* pthread_cond_wait atomically release mutex, Upon successful return,
255 * the mutex shall have been locked and shall be owned by the calling thread
257 tdm_mutex_locked = 0;
258 pthread_create(&private_thread->event_thread, NULL, _tdm_thread_main,
261 /* wait until the tdm thread starts */
262 pthread_cond_wait(&private_thread->event_cond, &private_display->lock);
263 tdm_mutex_locked = 1;
265 TDM_INFO("using a TDM event thread. pipe(%d,%d) sub_pipe(%d,%d)",
266 private_thread->pipe[0], private_thread->pipe[1],
267 private_thread->sub_pipe[0], private_thread->sub_pipe[1]);
269 return TDM_ERROR_NONE;
273 tdm_thread_deinit(tdm_private_loop *private_loop)
275 tdm_private_display *private_display;
276 tdm_private_thread_cb *cb = NULL, *hh = NULL;
279 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
281 for (i = 0; i < TDM_THREAD_CB_MAX; i++)
282 find_funcs[i] = NULL;
284 if (!private_loop->private_thread)
287 if (private_loop->private_thread->sub_event_source)
288 tdm_event_loop_source_remove(private_loop->private_thread->sub_event_source);
290 pthread_cancel(private_loop->private_thread->event_thread);
292 private_display = private_loop->dpy;
294 /* before falling into the block of pthread_join, we have to unlock the mutex
295 * for subthread to use the mutex.
297 _pthread_mutex_unlock(&private_display->lock);
298 pthread_join(private_loop->private_thread->event_thread, NULL);
302 pthread_mutex_destroy(&cb_list_lock);
304 LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &cb_list[0], link) {
305 _tdm_thread_free_cb(cb);
307 LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &cb_list[1], link) {
308 _tdm_thread_free_cb(cb);
311 if (private_loop->private_thread->pipe[0] >= 0)
312 close(private_loop->private_thread->pipe[0]);
313 if (private_loop->private_thread->pipe[1] >= 0)
314 close(private_loop->private_thread->pipe[1]);
316 if (private_loop->private_thread->sub_pipe[0] >= 0)
317 close(private_loop->private_thread->sub_pipe[0]);
318 if (private_loop->private_thread->sub_pipe[1] >= 0)
319 close(private_loop->private_thread->sub_pipe[1]);
321 pthread_cond_destroy(&private_loop->private_thread->event_cond);
323 free(private_loop->private_thread);
324 private_loop->private_thread = NULL;
325 keep_private_thread = NULL;
327 TDM_INFO("Finish a TDM event thread");
331 tdm_thread_get_fd(tdm_private_loop *private_loop)
333 tdm_private_thread *private_thread;
336 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
337 TDM_RETURN_VAL_IF_FAIL(private_loop, -1);
338 TDM_RETURN_VAL_IF_FAIL(private_loop->private_thread, -1);
340 private_thread = private_loop->private_thread;
342 /* seems like ticky. but easy way to use the same APIs for both threads */
343 in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
346 return private_thread->pipe[0];
348 return private_thread->sub_pipe[0];
352 tdm_thread_send_cb(tdm_private_loop *private_loop, tdm_thread_cb_base *base)
354 tdm_private_thread *private_thread;
358 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
359 TDM_RETURN_VAL_IF_FAIL(base, TDM_ERROR_INVALID_PARAMETER);
360 TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_INVALID_PARAMETER);
361 TDM_RETURN_VAL_IF_FAIL(private_loop->private_thread, TDM_ERROR_INVALID_PARAMETER);
363 private_thread = private_loop->private_thread;
365 /* seems like ticky. but easy way to use the same APIs for both threads */
366 in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
369 pipe = private_thread->sub_pipe[1];
371 pipe = private_thread->pipe[1];
373 if (tdm_debug_module & TDM_DEBUG_THREAD)
374 TDM_INFO("fd(%d) type(%s), length(%d)", pipe, tdm_cb_type_str(base->type), base->length);
376 len = write(pipe, base, base->length);
377 if (len != base->length) {
378 TDM_ERR("write failed (%d != %d): %m", (int)len, base->length);
379 return TDM_ERROR_OPERATION_FAILED;
382 if (tdm_debug_module & TDM_DEBUG_THREAD)
383 TDM_INFO("[%s] write fd(%d) length(%d)", (in_main) ? "main" : "sub", pipe, len);
385 return TDM_ERROR_NONE;
389 tdm_thread_handle_cb(tdm_private_loop *private_loop)
391 tdm_private_thread *private_thread;
392 tdm_thread_cb_base *base;
395 int len, pipe, in_main;
396 tdm_error ret = TDM_ERROR_NONE;
398 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
399 TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_INVALID_PARAMETER);
400 TDM_RETURN_VAL_IF_FAIL(private_loop->private_thread, TDM_ERROR_INVALID_PARAMETER);
402 private_thread = private_loop->private_thread;
404 /* seems like ticky. but easy way to use the same APIs for both threads */
405 in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
408 pipe = private_thread->pipe[0];
410 pipe = private_thread->sub_pipe[0];
413 len = read(pipe, buffer, sizeof buffer);
414 } while (len < 0 && errno == EINTR);
416 if (tdm_debug_module & TDM_DEBUG_THREAD)
417 TDM_INFO("[%s] read fd(%d) length(%d)", (in_main) ? "main" : "sub", pipe, len);
420 TDM_ERR("read failed: errno(%d), len(%d) %m", errno, len);
421 return TDM_ERROR_OPERATION_FAILED;
425 return TDM_ERROR_NONE;
427 if (len < sizeof * base) {
428 TDM_ERR("read failed: len(%d)", len);
429 return TDM_ERROR_OPERATION_FAILED;
434 base = (tdm_thread_cb_base*)&buffer[i];
435 if (tdm_debug_module & TDM_DEBUG_THREAD)
436 TDM_INFO("type(%s), length(%d)", tdm_cb_type_str(base->type), base->length);
437 switch (base->type) {
438 case TDM_THREAD_CB_OUTPUT_COMMIT:
439 case TDM_THREAD_CB_OUTPUT_VBLANK:
440 case TDM_THREAD_CB_OUTPUT_STATUS:
441 case TDM_THREAD_CB_OUTPUT_DPMS:
442 case TDM_THREAD_CB_PP_DONE:
443 case TDM_THREAD_CB_CAPTURE_DONE:
444 case TDM_THREAD_CB_VBLANK_SW:
445 case TDM_THREAD_CB_VBLANK_CREATE:
446 case TDM_THREAD_CB_NEED_VALIDATE:
447 ret = tdm_thread_cb_call(NULL, base);
448 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
456 return TDM_ERROR_NONE;
460 tdm_thread_in_display_thread(pid_t tid)
462 if (!keep_private_thread)
465 /* DON'T check TDM_MUTEX_IS_LOCKED here */
467 return (keep_private_thread->display_tid == tid) ? 1 : 0;
471 tdm_thread_is_running(void)
473 /* DON'T check TDM_MUTEX_IS_LOCKED here */
475 return (keep_private_thread) ? 1 : 0;
479 _tdm_thread_free_cb(tdm_private_thread_cb *cb)
481 if (tdm_debug_module & TDM_DEBUG_THREAD)
482 TDM_INFO("cb(%p) removed", cb);
484 assert(LIST_IS_EMPTY(&cb->call_link));
490 static tdm_private_thread_cb *
491 _tdm_thread_find_cb(struct list_head *list, void *object, tdm_thread_cb_type cb_type,
492 void *cb_data, tdm_thread_cb func, void *user_data, pid_t caller_tid)
494 tdm_private_thread_cb *cb = NULL;
496 LIST_FOR_EACH_ENTRY(cb, list, link) {
497 if (cb->object == object &&
498 cb->cb_type == cb_type &&
499 cb->cb_data == cb_data &&
501 cb->user_data == user_data &&
502 cb->owner_tid == caller_tid)
510 tdm_thread_cb_set_find_func(tdm_thread_cb_type cb_type, tdm_thread_find_object func)
512 TDM_RETURN_IF_FAIL(cb_type > 0);
514 if (func && find_funcs[cb_type])
515 TDM_NEVER_GET_HERE();
517 find_funcs[cb_type] = func;
521 tdm_thread_cb_add(void *object, tdm_thread_cb_type cb_type, void *cb_data, tdm_thread_cb func, void *user_data)
523 tdm_private_thread_cb *cb = NULL;
525 struct list_head *list;
527 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
528 TDM_RETURN_VAL_IF_FAIL(object != NULL, TDM_ERROR_INVALID_PARAMETER);
529 TDM_RETURN_VAL_IF_FAIL(cb_type > 0, TDM_ERROR_INVALID_PARAMETER);
530 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
532 caller_tid = syscall(SYS_gettid);
534 pthread_mutex_lock(&cb_list_lock);
536 if (tdm_thread_in_display_thread(caller_tid))
541 cb = _tdm_thread_find_cb(list, object, cb_type, cb_data, func, user_data, caller_tid);
543 pthread_mutex_unlock(&cb_list_lock);
544 TDM_ERR("can't be added twice with same data");
545 return TDM_ERROR_BAD_REQUEST;
548 cb = calloc(1, sizeof *cb);
550 pthread_mutex_unlock(&cb_list_lock);
551 TDM_ERR("calloc failed");
552 return TDM_ERROR_OUT_OF_MEMORY;
555 LIST_ADDTAIL(&cb->link, list);
556 LIST_INITHEAD(&cb->call_link);
559 cb->cb_type = cb_type;
560 cb->cb_data = cb_data;
562 cb->user_data = user_data;
563 cb->owner_tid = caller_tid;
565 if (tdm_debug_module & TDM_DEBUG_THREAD)
566 TDM_INFO("cb_type(%s) cb(%p) added", tdm_cb_type_str(cb_type), cb);
568 pthread_mutex_unlock(&cb_list_lock);
570 return TDM_ERROR_NONE;
574 tdm_thread_cb_remove(void *object, tdm_thread_cb_type cb_type, void *cb_data, tdm_thread_cb func, void *user_data)
576 tdm_private_thread_cb *cb;
578 struct list_head *list;
580 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
581 TDM_RETURN_IF_FAIL(object != NULL);
582 TDM_RETURN_IF_FAIL(cb_type > 0);
583 TDM_RETURN_IF_FAIL(func != NULL);
585 caller_tid = syscall(SYS_gettid);
587 pthread_mutex_lock(&cb_list_lock);
589 if (tdm_thread_in_display_thread(caller_tid))
594 cb = _tdm_thread_find_cb(list, object, cb_type, cb_data, func, user_data, caller_tid);
596 pthread_mutex_unlock(&cb_list_lock);
600 _tdm_thread_free_cb(cb);
601 pthread_mutex_unlock(&cb_list_lock);
604 /* when call a callback, we check both cb_base's type and cb_base's data,
605 * because a callback is added with cb_type and cb_data.
608 tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base)
610 tdm_private_display *private_display = tdm_display_get();
611 tdm_private_thread_cb *cb = NULL, *hh = NULL;
612 int handler_in_other_thread = 0;
614 struct list_head *list, *other_list;
615 struct list_head call_list;
616 static pid_t waiting_tid = 0;
617 static tdm_thread_cb_type waiting_cb_type = TDM_THREAD_CB_NONE;
620 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
621 TDM_RETURN_VAL_IF_FAIL(cb_base != NULL, TDM_ERROR_INVALID_PARAMETER);
622 TDM_RETURN_VAL_IF_FAIL(cb_base->type > 0, TDM_ERROR_INVALID_PARAMETER);
623 TDM_RETURN_VAL_IF_FAIL(cb_base->length > 0, TDM_ERROR_INVALID_PARAMETER);
624 TDM_RETURN_VAL_IF_FAIL(cb_base->object_stamp > 0, TDM_ERROR_INVALID_PARAMETER);
626 caller_tid = syscall(SYS_gettid);
628 assert(find_funcs[cb_base->type] != NULL);
630 /* handling only output-status as sync */
631 if (cb_base->type == TDM_THREAD_CB_OUTPUT_STATUS) {
632 TDM_RETURN_VAL_IF_FAIL(cb_base->sync == 1, TDM_ERROR_INVALID_PARAMETER);
634 TDM_RETURN_VAL_IF_FAIL(cb_base->sync == 0, TDM_ERROR_INVALID_PARAMETER);
638 object = find_funcs[cb_base->type](private_display, cb_base->object_stamp);
640 TDM_WRN("%p gone", object);
641 return TDM_ERROR_NONE;
645 pthread_mutex_lock(&cb_list_lock);
647 if (tdm_thread_in_display_thread(caller_tid)) {
649 other_list = &cb_list[1];
651 other_list = &cb_list[0];
655 LIST_INITHEAD(&call_list);
657 LIST_FOR_EACH_ENTRY_SAFE(cb, hh, list, link) {
658 if (cb->object != object ||
659 cb->cb_type != cb_base->type ||
660 cb->cb_data != cb_base->data)
663 LIST_ADDTAIL(&cb->call_link, &call_list);
666 if (!LIST_IS_EMPTY(&call_list)) {
667 LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &call_list, call_link) {
668 LIST_DELINIT(&cb->call_link);
669 if (tdm_debug_module & TDM_DEBUG_THREAD)
670 TDM_INFO("cb_type(%s) cb(%p) calling", tdm_cb_type_str(cb->cb_type), cb);
671 pthread_mutex_unlock(&cb_list_lock);
672 cb->func(private_display, cb->object, cb_base, cb->user_data);
673 pthread_mutex_lock(&cb_list_lock);
677 pthread_mutex_unlock(&cb_list_lock);
679 assert(LIST_IS_EMPTY(&call_list));
681 if (waiting_tid == 0 || waiting_cb_type != cb_base->type) {
682 LIST_FOR_EACH_ENTRY_SAFE(cb, hh, other_list, link) {
683 if (cb->object != object ||
684 cb->cb_type != cb_base->type ||
685 cb->cb_data != cb_base->data)
688 handler_in_other_thread = 1;
693 if (!handler_in_other_thread) {
694 if (keep_private_thread) {
697 waiting_cb_type = TDM_THREAD_CB_NONE;
698 pthread_cond_signal(&keep_private_thread->event_cond);
699 if (tdm_debug_module & TDM_DEBUG_THREAD)
700 TDM_INFO("pthread broadcase");
703 if (tdm_debug_module & TDM_DEBUG_THREAD)
704 TDM_INFO("'%s' thread_cb done(sync:%d)", tdm_cb_type_str(cb_base->type), cb_base->sync);
705 return TDM_ERROR_NONE;
708 /* Once we reach here, it means that keep_private_thread is not NULL.
709 * Just make the crash. Avoiding it is not going to help us.
711 ret = tdm_thread_send_cb(private_display->private_loop, cb_base);
712 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
714 /* waiting until all cb are done in another thread */
716 if (tdm_debug_module & TDM_DEBUG_THREAD)
717 TDM_INFO("pthread wait");
719 /* pthread_cond_wait atomically release mutex, Upon successful return,
720 * the mutex shall have been locked and shall be owned by the calling thread
722 tdm_mutex_locked = 0;
723 waiting_tid = caller_tid;
724 waiting_cb_type = cb_base->type;
726 pthread_cond_wait(&keep_private_thread->event_cond, &private_display->lock);
727 tdm_mutex_locked = 1;
730 if (tdm_debug_module & TDM_DEBUG_THREAD)
731 TDM_INFO("'%s' thread_cb done(sync:%d)", tdm_cb_type_str(cb_base->type), cb_base->sync);
733 return TDM_ERROR_NONE;