#include "config.h"
#endif
-#include <sys/socket.h>
-
-#include "tdm.h"
#include "tdm_private.h"
-#include "tdm_list.h"
static tdm_private_thread *keep_private_thread;
struct _tdm_private_thread {
tdm_private_loop *private_loop;
+ pthread_cond_t event_cond;
pthread_t event_thread;
pid_t display_tid;
pid_t thread_tid;
- /* 0: read, 1: write */
+ /* 0: read, 1: write (tdm-thread -> display-thread) */
int pipe[2];
+
+ /* 0: read, 1: write (tdm-thread <- display-thread) */
+ int sub_pipe[2];
+ tdm_event_loop_source *sub_event_source;
};
+typedef struct _tdm_private_thread_cb {
+ struct list_head link;
+ struct list_head call_link;
+
+ void *object;
+ tdm_thread_cb_type cb_type;
+ void *cb_data;
+ tdm_thread_cb func;
+ void *user_data;
+
+ pid_t owner_tid;
+ unsigned int called;
+} tdm_private_thread_cb;
+
+static tdm_thread_find_object find_funcs[TDM_THREAD_CB_MAX] = {0, };
+static struct list_head cb_list;
+
+static void _tdm_thread_free_cb(tdm_private_thread_cb *cb);
+
+static tdm_error
+_tdm_thread_handle_events(int fd, tdm_event_loop_mask mask, void *user_data)
+{
+ tdm_private_loop *private_loop = user_data;
+ tdm_error ret;
+
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+ TDM_RETURN_VAL_IF_FAIL(private_loop != NULL, TDM_ERROR_OPERATION_FAILED);
+ TDM_RETURN_VAL_IF_FAIL(private_loop->dpy != NULL, TDM_ERROR_OPERATION_FAILED);
+
+ ret = tdm_thread_handle_cb(private_loop);
+
+ TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
+
+ return TDM_ERROR_NONE;
+}
+
static void*
_tdm_thread_main(void *data)
{
int fd;
struct pollfd fds;
int ret;
+ tdm_error error;
/* Not lock/unlock for the private_thread and private_loop structure
* because they won't be destroyed as long as tdm thread is running.
TDM_INFO("display_tid:%d, thread_tid: %d",
private_thread->display_tid, private_thread->thread_tid);
+ /* fd SHOULD be the same with sub_pipe[0] to make sure that using
+ * tdm_thread_get_fd, tdm_thread_send_cb, tdm_thread_handle_cb in
+ * both threads is fine. Otherwise, assert.
+ */
+ tdm_display_lock(private_loop->dpy);
+ assert(tdm_thread_get_fd(private_loop) == private_thread->sub_pipe[0]);
+
+ private_thread->sub_event_source =
+ tdm_event_loop_add_fd_handler(private_loop->dpy,
+ private_thread->sub_pipe[0],
+ TDM_EVENT_LOOP_READABLE,
+ _tdm_thread_handle_events,
+ private_loop,
+ &error);
+ TDM_GOTO_IF_FAIL(error == TDM_ERROR_NONE, exit_thread);
+ TDM_GOTO_IF_FAIL(private_thread->sub_event_source != NULL, exit_thread);
+
+ pthread_cond_signal(&private_thread->event_cond);
+
+ /* mutex shall be locked by the thread calling pthread_cond_signal() */
+ tdm_display_unlock(private_loop->dpy);
+
fd = tdm_event_loop_get_fd(private_loop->dpy);
if (fd < 0) {
TDM_ERR("couldn't get fd");
fds.revents = 0;
while (1) {
- if (tdm_debug_module & TDM_DEBUG_THREAD)
+ if (tdm_debug_module & TDM_DEBUG_EVENT)
TDM_INFO("server flush");
tdm_event_loop_flush(private_loop->dpy);
- if (tdm_debug_module & TDM_DEBUG_THREAD)
+ if (tdm_debug_module & TDM_DEBUG_EVENT)
TDM_INFO("fd(%d) polling in", fd);
ret = poll(&fds, 1, -1);
- if (tdm_debug_module & TDM_DEBUG_THREAD)
+ if (tdm_debug_module & TDM_DEBUG_EVENT)
TDM_INFO("fd(%d) polling out", fd);
if (ret < 0) {
}
}
- if (tdm_debug_module & TDM_DEBUG_THREAD)
+ if (tdm_debug_module & TDM_DEBUG_EVENT)
TDM_INFO("thread got events");
if (tdm_event_loop_dispatch(private_loop->dpy) < 0)
}
exit_thread:
+ tdm_display_unlock(private_loop->dpy);
pthread_exit(NULL);
}
{
tdm_private_display *private_display;
tdm_private_thread *private_thread;
- const char *thread;
+ int thread, i;
TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(private_loop->dpy, TDM_ERROR_OPERATION_FAILED);
private_display = private_loop->dpy;
TDM_RETURN_VAL_IF_FAIL(private_display->private_loop, TDM_ERROR_OPERATION_FAILED);
+ for (i = 0; i < TDM_THREAD_CB_MAX; i++)
+ find_funcs[i] = NULL;
+
+ LIST_INITHEAD(&cb_list);
+
if (private_loop->private_thread)
return TDM_ERROR_NONE;
/* enable as default */
- thread = getenv("TDM_THREAD");
- if (!thread || strncmp(thread, "1", 1)) {
- TDM_INFO("not using a TDM event thread: %s", (thread) ? thread : "none");
+ thread = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1);
+ if (!thread) {
+ TDM_INFO("not using a TDM event thread");
return TDM_ERROR_NONE;
}
return TDM_ERROR_OUT_OF_MEMORY;
}
+ if (pthread_cond_init(&private_thread->event_cond, NULL)) {
+ TDM_ERR("pthread_cond_init failed: %m");
+ free(private_thread);
+ return TDM_ERROR_OUT_OF_MEMORY;
+ }
+
if (pipe(private_thread->pipe) != 0) {
- TDM_ERR("socketpair failed: %m");
+ TDM_ERR("pipe failed: %m");
+ pthread_cond_destroy(&private_thread->event_cond);
free(private_thread);
return TDM_ERROR_OPERATION_FAILED;
}
+ if (pipe(private_thread->sub_pipe) != 0) {
+ TDM_ERR("sub_pipe failed: %m");
+ close(private_thread->pipe[0]);
+ close(private_thread->pipe[1]);
+ pthread_cond_destroy(&private_thread->event_cond);
+ free(private_thread);
+ return TDM_ERROR_OPERATION_FAILED;
+ }
+
+ keep_private_thread = private_thread;
+
private_thread->private_loop = private_loop;
private_loop->private_thread = private_thread;
private_thread->display_tid = syscall(SYS_gettid);
+ /* pthread_cond_wait atomically release mutex, Upon successful return,
+ * the mutex shall have been locked and shall be owned by the calling thread
+ */
+ tdm_mutex_locked = 0;
pthread_create(&private_thread->event_thread, NULL, _tdm_thread_main,
private_thread);
- keep_private_thread = private_thread;
+ /* wait until the tdm thread starts */
+ pthread_cond_wait(&private_thread->event_cond, &private_display->lock);
+ tdm_mutex_locked = 1;
- TDM_INFO("using a TDM event thread. pipe(%d,%d)",
- private_thread->pipe[0], private_thread->pipe[1]);
+ TDM_INFO("using a TDM event thread. pipe(%d,%d) sub_pipe(%d,%d)",
+ private_thread->pipe[0], private_thread->pipe[1],
+ private_thread->sub_pipe[0], private_thread->sub_pipe[1]);
return TDM_ERROR_NONE;
}
tdm_thread_deinit(tdm_private_loop *private_loop)
{
tdm_private_display *private_display;
+ tdm_private_thread_cb *cb = NULL, *hh = NULL;
+ int i;
TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
+ for (i = 0; i < TDM_THREAD_CB_MAX; i++)
+ find_funcs[i] = NULL;
+
if (!private_loop->private_thread)
return;
+ if (private_loop->private_thread->sub_event_source)
+ tdm_event_loop_source_remove(private_loop->private_thread->sub_event_source);
+
pthread_cancel(private_loop->private_thread->event_thread);
private_display = private_loop->dpy;
_pthread_mutex_unlock(&private_display->lock);
pthread_join(private_loop->private_thread->event_thread, NULL);
+ tdm_log_reset();
+
+ LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &cb_list, link) {
+ _tdm_thread_free_cb(cb);
+ }
+
if (private_loop->private_thread->pipe[0] >= 0)
close(private_loop->private_thread->pipe[0]);
if (private_loop->private_thread->pipe[1] >= 0)
close(private_loop->private_thread->pipe[1]);
+ if (private_loop->private_thread->sub_pipe[0] >= 0)
+ close(private_loop->private_thread->sub_pipe[0]);
+ if (private_loop->private_thread->sub_pipe[1] >= 0)
+ close(private_loop->private_thread->sub_pipe[1]);
+
+ pthread_cond_destroy(&private_loop->private_thread->event_cond);
+
free(private_loop->private_thread);
private_loop->private_thread = NULL;
keep_private_thread = NULL;
tdm_thread_get_fd(tdm_private_loop *private_loop)
{
tdm_private_thread *private_thread;
+ int in_main;
TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(private_loop, -1);
private_thread = private_loop->private_thread;
- return private_thread->pipe[0];
+ /* seems like ticky. but easy way to use the same APIs for both threads */
+ in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
+
+ if (in_main)
+ return private_thread->pipe[0];
+ else
+ return private_thread->sub_pipe[0];
}
INTERN tdm_error
{
tdm_private_thread *private_thread;
ssize_t len;
+ int pipe, in_main;
TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(base, TDM_ERROR_INVALID_PARAMETER);
private_thread = private_loop->private_thread;
+ /* seems like ticky. but easy way to use the same APIs for both threads */
+ in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
+
+ if (in_main)
+ pipe = private_thread->sub_pipe[1];
+ else
+ pipe = private_thread->pipe[1];
+
if (tdm_debug_module & TDM_DEBUG_THREAD)
- TDM_INFO("fd(%d) type(%d), length(%d)",
- private_thread->pipe[1], base->type, base->length);
+ TDM_INFO("fd(%d) type(%d), length(%d)", pipe, base->type, base->length);
- len = write(private_thread->pipe[1], base, base->length);
+ len = write(pipe, base, base->length);
if (len != base->length) {
TDM_ERR("write failed (%d != %d): %m", (int)len, base->length);
return TDM_ERROR_OPERATION_FAILED;
}
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("[%s] write fd(%d) length(%d)", (in_main) ? "main" : "sub", pipe, len);
+
return TDM_ERROR_NONE;
}
INTERN tdm_error
tdm_thread_handle_cb(tdm_private_loop *private_loop)
{
- tdm_private_display *private_display;
tdm_private_thread *private_thread;
tdm_thread_cb_base *base;
char buffer[1024];
- unsigned int len, i;
-
- /* DON'T check TDM_MUTEX_IS_LOCKED here */
+ unsigned int i;
+ int len, pipe, in_main;
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_INVALID_PARAMETER);
TDM_RETURN_VAL_IF_FAIL(private_loop->private_thread, TDM_ERROR_INVALID_PARAMETER);
private_thread = private_loop->private_thread;
- private_display = private_loop->dpy;
- len = read(private_thread->pipe[0], buffer, sizeof buffer);
+ /* seems like ticky. but easy way to use the same APIs for both threads */
+ in_main = tdm_thread_in_display_thread(syscall(SYS_gettid));
+
+ if (in_main)
+ pipe = private_thread->pipe[0];
+ else
+ pipe = private_thread->sub_pipe[0];
+
+ do {
+ len = read(pipe, buffer, sizeof buffer);
+ } while (len < 0 && errno == EINTR);
if (tdm_debug_module & TDM_DEBUG_THREAD)
- TDM_INFO("fd(%d) read length(%d)", private_thread->pipe[0], len);
+ TDM_INFO("[%s] read fd(%d) length(%d)", (in_main) ? "main" : "sub", pipe, len);
+
+ if (len < 0) {
+ TDM_ERR("read failed: errno(%d), len(%d) %m", errno, len);
+ return TDM_ERROR_OPERATION_FAILED;
+ }
if (len == 0)
return TDM_ERROR_NONE;
if (len < sizeof * base) {
- TDM_NEVER_GET_HERE();
+ TDM_ERR("read failed: len(%d)", len);
return TDM_ERROR_OPERATION_FAILED;
}
- _pthread_mutex_lock(&private_display->lock);
-
i = 0;
while (i < len) {
base = (tdm_thread_cb_base*)&buffer[i];
if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("type(%d), length(%d)", base->type, base->length);
switch (base->type) {
- case TDM_THREAD_CB_OUTPUT_COMMIT: {
- tdm_thread_cb_output_commit *output_commit = (tdm_thread_cb_output_commit*)base;
- tdm_output *output_backend =
- tdm_display_find_output_stamp(private_loop->dpy, output_commit->output_stamp);
- if (!output_backend) {
- TDM_WRN("no output(%ld)", output_commit->output_stamp);
- break;
- }
- tdm_output_cb_commit(output_backend, output_commit->sequence,
- output_commit->tv_sec, output_commit->tv_usec,
- output_commit->user_data);
- break;
- }
- case TDM_THREAD_CB_OUTPUT_VBLANK: {
- tdm_thread_cb_output_vblank *output_vblank = (tdm_thread_cb_output_vblank*)base;
- tdm_output *output_backend =
- tdm_display_find_output_stamp(private_loop->dpy, output_vblank->output_stamp);
- if (!output_backend) {
- TDM_WRN("no output(%ld)", output_vblank->output_stamp);
- break;
- }
- tdm_output_cb_vblank(output_backend, output_vblank->sequence,
- output_vblank->tv_sec, output_vblank->tv_usec,
- output_vblank->user_data);
- break;
- }
- case TDM_THREAD_CB_OUTPUT_STATUS: {
- tdm_thread_cb_output_status *output_status = (tdm_thread_cb_output_status*)base;
- tdm_output *output_backend =
- tdm_display_find_output_stamp(private_loop->dpy, output_status->output_stamp);
- if (!output_backend) {
- TDM_WRN("no output(%ld)", output_status->output_stamp);
- break;
- }
- tdm_output_cb_status(output_backend, output_status->status,
- output_status->user_data);
- break;
- }
- case TDM_THREAD_CB_PP_DONE: {
- tdm_thread_cb_pp_done *pp_done = (tdm_thread_cb_pp_done*)base;
- tdm_pp *pp_backend =
- tdm_pp_find_stamp(private_loop->dpy, pp_done->pp_stamp);
- if (!pp_backend) {
- TDM_WRN("no pp(%ld)", pp_done->pp_stamp);
- break;
- }
- tdm_pp_cb_done(pp_backend, pp_done->src, pp_done->dst, pp_done->user_data);
+ case TDM_THREAD_CB_OUTPUT_COMMIT:
+ case TDM_THREAD_CB_OUTPUT_VBLANK:
+ case TDM_THREAD_CB_OUTPUT_CHANGE:
+ case TDM_THREAD_CB_PP_DONE:
+ case TDM_THREAD_CB_CAPTURE_DONE:
+ case TDM_THREAD_CB_VBLANK_SW:
+ case TDM_THREAD_CB_VBLANK_CREATE:
+ case TDM_THREAD_CB_NEED_VALIDATE:
+ tdm_thread_cb_call(NULL, base);
break;
- }
- case TDM_THREAD_CB_CAPTURE_DONE: {
- tdm_thread_cb_capture_done *capture_done = (tdm_thread_cb_capture_done*)base;
- tdm_capture *capture_backend =
- tdm_capture_find_stamp(private_loop->dpy, capture_done->capture_stamp);
- if (!capture_backend) {
- TDM_WRN("no capture(%ld)", capture_done->capture_stamp);
- break;
- }
- tdm_capture_cb_done(capture_backend, capture_done->buffer, capture_done->user_data);
- break;
- }
default:
break;
}
i += base->length;
}
- _pthread_mutex_unlock(&private_display->lock);
-
return TDM_ERROR_NONE;
}
return (keep_private_thread) ? 1 : 0;
}
+
+static void
+_tdm_thread_free_cb(tdm_private_thread_cb *cb)
+{
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("cb(%p) removed", cb);
+
+ assert(LIST_IS_EMPTY(&cb->call_link));
+
+ LIST_DEL(&cb->link);
+ free(cb);
+}
+
+static tdm_private_thread_cb *
+_tdm_thread_find_cb(void *object, tdm_thread_cb_type cb_type, void *cb_data, tdm_thread_cb func, void *user_data, pid_t owner_tid)
+{
+ tdm_private_thread_cb *cb = NULL;
+
+ LIST_FOR_EACH_ENTRY(cb, &cb_list, link) {
+ if (cb->object == object &&
+ cb->cb_type == cb_type &&
+ cb->cb_data == cb_data &&
+ cb->func == func &&
+ cb->user_data == user_data &&
+ cb->owner_tid == owner_tid)
+ return cb;
+ }
+
+ return NULL;
+}
+
+static void
+_tdm_thread_reset_cb(tdm_thread_cb_type cb_type)
+{
+ tdm_private_thread_cb *cb = NULL;
+
+ LIST_FOR_EACH_ENTRY(cb, &cb_list, link) {
+ if (cb->cb_type == cb_type)
+ cb->called = 0;
+ }
+}
+
+INTERN void
+tdm_thread_cb_set_find_func(tdm_thread_cb_type cb_type, tdm_thread_find_object func)
+{
+ TDM_RETURN_IF_FAIL(cb_type > 0);
+
+ if (func && find_funcs[cb_type])
+ TDM_NEVER_GET_HERE();
+
+ find_funcs[cb_type] = func;
+}
+
+INTERN tdm_error
+tdm_thread_cb_add(void *object, tdm_thread_cb_type cb_type, void *cb_data, tdm_thread_cb func, void *user_data)
+{
+ tdm_private_thread_cb *cb = NULL;
+ pid_t caller_tid;
+
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+ TDM_RETURN_VAL_IF_FAIL(object != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(cb_type > 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ caller_tid = syscall(SYS_gettid);
+
+ cb = _tdm_thread_find_cb(object, cb_type, cb_data, func, user_data, caller_tid);
+ if (cb) {
+ TDM_ERR("can't be added twice with same data");
+#if 1
+ assert(0);
+#endif
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ cb = calloc(1, sizeof *cb);
+ if (!cb) {
+ TDM_ERR("calloc failed");
+ return TDM_ERROR_OUT_OF_MEMORY;
+ }
+
+ LIST_ADDTAIL(&cb->link, &cb_list);
+ LIST_INITHEAD(&cb->call_link);
+
+ cb->object = object;
+ cb->cb_type = cb_type;
+ cb->cb_data = cb_data;
+ cb->func = func;
+ cb->user_data = user_data;
+ cb->owner_tid = caller_tid;
+
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("cb_type(%d) cb(%p) added", cb_type, cb);
+
+ return TDM_ERROR_NONE;
+}
+
+INTERN void
+tdm_thread_cb_remove(void *object, tdm_thread_cb_type cb_type, void *cb_data, tdm_thread_cb func, void *user_data)
+{
+ tdm_private_thread_cb *cb;
+ pid_t caller_tid;
+
+ TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
+ TDM_RETURN_IF_FAIL(object != NULL);
+ TDM_RETURN_IF_FAIL(cb_type > 0);
+ TDM_RETURN_IF_FAIL(func != NULL);
+
+ caller_tid = syscall(SYS_gettid);
+
+ cb = _tdm_thread_find_cb(object, cb_type, cb_data, func, user_data, caller_tid);
+ if (!cb)
+ return;
+
+ _tdm_thread_free_cb(cb);
+}
+
+/* when call a callback, we check both cb_base's type and cb_base's data,
+ * because a callback is added with cb_type and cb_data.
+ */
+INTERN tdm_error
+tdm_thread_cb_call(void *object, tdm_thread_cb_base *cb_base)
+{
+ tdm_private_display *private_display = tdm_display_get();
+ tdm_private_thread_cb *cb = NULL, *hh = NULL;
+ int handler_in_other_thread = 0;
+ pid_t caller_tid;
+ struct list_head call_list;
+ tdm_error ret;
+
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+ TDM_RETURN_VAL_IF_FAIL(cb_base != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(cb_base->type > 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(cb_base->length > 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(cb_base->sync == 0 || cb_base->sync == 1, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(cb_base->object_stamp > 0, TDM_ERROR_INVALID_PARAMETER);
+
+ caller_tid = syscall(SYS_gettid);
+
+ assert(find_funcs[cb_base->type] != NULL);
+
+ if (!object) {
+ object = find_funcs[cb_base->type](private_display, cb_base->object_stamp);
+ if (!object) {
+ TDM_WRN("%p gone", object);
+ return TDM_ERROR_NONE;
+ }
+ }
+
+ LIST_INITHEAD(&call_list);
+
+ LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &cb_list, link) {
+ if (cb->called ||
+ cb->object != object ||
+ cb->cb_type != cb_base->type ||
+ cb->cb_data != cb_base->data)
+ continue;
+
+ if (cb->owner_tid == caller_tid)
+ LIST_ADDTAIL(&cb->call_link, &call_list);
+ else
+ handler_in_other_thread = 1;
+ }
+
+ if (!LIST_IS_EMPTY(&call_list)) {
+ LIST_FOR_EACH_ENTRY_SAFE(cb, hh, &call_list, call_link) {
+ LIST_DELINIT(&cb->call_link);
+ cb->called = 1;
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("cb_type(%d) cb(%p) called", cb->cb_type, cb);
+ cb->func(private_display, cb->object, cb_base, cb->user_data);
+ }
+ }
+
+ assert(LIST_IS_EMPTY(&call_list));
+
+ if (!handler_in_other_thread) {
+ _tdm_thread_reset_cb(cb_base->type);
+ if (keep_private_thread) {
+ if (cb_base->sync) {
+ pthread_cond_signal(&keep_private_thread->event_cond);
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("pthread broadcase");
+ }
+ }
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("'%s' thread_cb done(sync:%d)", tdm_cb_type_str(cb_base->type), cb_base->sync);
+ return TDM_ERROR_NONE;
+ }
+
+ /* Once we reach here, it means that keep_private_thread is not NULL.
+ * Just make the crash. Avoiding it is not going to help us.
+ */
+ ret = tdm_thread_send_cb(private_display->private_loop, cb_base);
+ TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
+
+ /* waiting until all cb are done in another thread */
+ if (cb_base->sync) {
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("pthread wait");
+
+ /* pthread_cond_wait atomically release mutex, Upon successful return,
+ * the mutex shall have been locked and shall be owned by the calling thread
+ */
+ tdm_mutex_locked = 0;
+ pthread_cond_wait(&keep_private_thread->event_cond, &private_display->lock);
+ tdm_mutex_locked = 1;
+ }
+
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
+ TDM_INFO("'%s' thread_cb done(sync:%d)", tdm_cb_type_str(cb_base->type), cb_base->sync);
+
+ return TDM_ERROR_NONE;
+}