/**************************************************************************
-
-libtdm
-
-Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: Eunchul Kim <chulspro.kim@samsung.com>,
- JinYoung Jeon <jy0.jeon@samsung.com>,
- Taeheon Kim <th908.kim@samsung.com>,
- YoungJun Cho <yj44.cho@samsung.com>,
- SooChan Lim <sc1.lim@samsung.com>,
- Boram Park <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
+ * JinYoung Jeon <jy0.jeon@samsung.com>,
+ * Taeheon Kim <th908.kim@samsung.com>,
+ * YoungJun Cho <yj44.cho@samsung.com>,
+ * SooChan Lim <sc1.lim@samsung.com>,
+ * Boram Park <sc1.lim@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
**************************************************************************/
#ifdef HAVE_CONFIG_H
#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;
private_thread->thread_tid = syscall(SYS_gettid);
TDM_INFO("display_tid:%d, thread_tid: %d",
- private_thread->display_tid, private_thread->thread_tid);
+ private_thread->display_tid, private_thread->thread_tid);
fd = tdm_event_loop_get_fd(private_loop->dpy);
if (fd < 0) {
fds.revents = 0;
while (1) {
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("server flush");
tdm_event_loop_flush(private_loop->dpy);
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("fd(%d) polling in", fd);
ret = poll(&fds, 1, -1);
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("fd(%d) polling out", fd);
if (ret < 0) {
- if (errno == EBUSY) /* normal case */
+ if (errno == EINTR || errno == EAGAIN) /* normal case */
continue;
else {
TDM_ERR("poll failed: %m");
}
}
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("thread got events");
if (tdm_event_loop_dispatch(private_loop->dpy) < 0)
tdm_private_thread *private_thread;
const char *thread;
+ 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;
/* 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");
+ TDM_INFO("not using a TDM event thread: %s", (thread) ? thread : "none");
return TDM_ERROR_NONE;
}
- private_thread = calloc(1, sizeof *private_thread);
+ private_thread = calloc(1, sizeof * private_thread);
if (!private_thread) {
TDM_ERR("alloc failed");
return TDM_ERROR_OUT_OF_MEMORY;
private_thread->display_tid = syscall(SYS_gettid);
pthread_create(&private_thread->event_thread, NULL, _tdm_thread_main,
- private_thread);
+ private_thread);
+
+ keep_private_thread = private_thread;
TDM_INFO("using a TDM event thread. pipe(%d,%d)",
- private_thread->pipe[0], private_thread->pipe[1]);
+ private_thread->pipe[0], private_thread->pipe[1]);
return TDM_ERROR_NONE;
}
INTERN void
tdm_thread_deinit(tdm_private_loop *private_loop)
{
+ tdm_private_display *private_display;
+
+ TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
+
if (!private_loop->private_thread)
return;
pthread_cancel(private_loop->private_thread->event_thread);
+
+ private_display = private_loop->dpy;
+
+ /* before falling into the block of pthread_join, we have to unlock the mutex
+ * for subthread to use the mutex.
+ */
+ _pthread_mutex_unlock(&private_display->lock);
pthread_join(private_loop->private_thread->event_thread, NULL);
if (private_loop->private_thread->pipe[0] >= 0)
free(private_loop->private_thread);
private_loop->private_thread = NULL;
+ keep_private_thread = NULL;
TDM_INFO("Finish a TDM event thread");
}
{
tdm_private_thread *private_thread;
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(private_loop, -1);
TDM_RETURN_VAL_IF_FAIL(private_loop->private_thread, -1);
tdm_private_thread *private_thread;
ssize_t len;
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(base, TDM_ERROR_INVALID_PARAMETER);
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;
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("fd(%d) type(%d), length(%d)",
- private_thread->pipe[1], base->type, base->length);
+ private_thread->pipe[1], base->type, base->length);
len = write(private_thread->pipe[1], base, base->length);
if (len != base->length) {
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];
- int len, i;
+ unsigned int i;
+ int len;
+
+ /* DON'T check TDM_MUTEX_IS_LOCKED here */
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);
+ do {
+ len = read(private_thread->pipe[0], buffer, sizeof buffer);
+ } while (len < 0 && errno == EINTR);
- if (tdm_debug_thread)
+ if (tdm_debug_module & TDM_DEBUG_THREAD)
TDM_INFO("fd(%d) read length(%d)", private_thread->pipe[0], 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();
+ if (len < sizeof * base) {
+ 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_thread)
+ 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:
- {
+ 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);
+ TDM_WRN("no output(%f)", 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);
+ output_commit->tv_sec, output_commit->tv_usec,
+ output_commit->user_data);
break;
}
- case TDM_THREAD_CB_OUTPUT_VBLANK:
- {
+ 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);
+ TDM_WRN("no output(%f)", 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);
+ output_vblank->tv_sec, output_vblank->tv_usec,
+ output_vblank->user_data);
break;
}
- case TDM_THREAD_CB_OUTPUT_STATUS:
- {
+ case TDM_THREAD_CB_OUTPUT_STATUS: {
+ /* LCOV_EXCL_START */
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);
+ TDM_WRN("no output(%f)", output_status->output_stamp);
break;
}
tdm_output_cb_status(output_backend, output_status->status,
- output_status->user_data);
+ output_status->user_data);
break;
+ /* LCOV_EXCL_STOP */
}
- case TDM_THREAD_CB_PP_DONE:
- {
+ case TDM_THREAD_CB_OUTPUT_DPMS: {
+ /* LCOV_EXCL_START */
+ tdm_thread_cb_output_dpms *output_dpms = (tdm_thread_cb_output_dpms*)base;
+ tdm_output *output_backend =
+ tdm_display_find_output_stamp(private_loop->dpy, output_dpms->output_stamp);
+ if (!output_backend) {
+ TDM_WRN("no output(%f)", output_dpms->output_stamp);
+ break;
+ }
+ tdm_output_cb_dpms(output_backend, output_dpms->dpms, output_dpms->user_data);
+ break;
+ /* LCOV_EXCL_STOP */
+ }
+ 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);
+ TDM_WRN("no pp(%f)", pp_done->pp_stamp);
break;
}
tdm_pp_cb_done(pp_backend, pp_done->src, pp_done->dst, pp_done->user_data);
break;
}
- case TDM_THREAD_CB_CAPTURE_DONE:
- {
+ 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);
+ TDM_WRN("no capture(%f)", capture_done->capture_stamp);
break;
}
tdm_capture_cb_done(capture_backend, capture_done->buffer, capture_done->user_data);
break;
}
+ case TDM_THREAD_CB_VBLANK_SW: {
+ tdm_thread_cb_vblank_sw *vblank_sw = (tdm_thread_cb_vblank_sw*)base;
+ tdm_vblank_cb_vblank_SW(NULL, vblank_sw->vblank_stamp);
+ break;
+ }
+ case TDM_THREAD_CB_VBLANK_CREATE: {
+ tdm_thread_cb_vblank_create *vblank_create = (tdm_thread_cb_vblank_create*)base;
+ tdm_vblank_cb_vblank_create(NULL, vblank_create->vblank_stamp);
+ break;
+ }
+ case TDM_THREAD_CB_NEED_VALIDATE: {
+ tdm_thread_cb_need_validate *ev = (tdm_thread_cb_need_validate*)base;
+ tdm_output_cb_need_validate(ev->o);
+ break;
+ }
default:
break;
}
i += base->length;
}
- tdm_event_loop_flush(private_loop->dpy);
+ _pthread_mutex_unlock(&private_display->lock);
return TDM_ERROR_NONE;
}
INTERN int
-tdm_thread_in_display_thread(tdm_private_loop *private_loop, pid_t tid)
+tdm_thread_in_display_thread(pid_t tid)
{
- tdm_private_thread *private_thread;
+ if (!keep_private_thread)
+ return 1;
- TDM_RETURN_VAL_IF_FAIL(private_loop, 1);
+ /* DON'T check TDM_MUTEX_IS_LOCKED here */
- if (!private_loop->private_thread)
- return 1;
+ return (keep_private_thread->display_tid == tid) ? 1 : 0;
+}
- private_thread = private_loop->private_thread;
+INTERN int
+tdm_thread_is_running(void)
+{
+ /* DON'T check TDM_MUTEX_IS_LOCKED here */
- return (private_thread->display_tid == tid) ? 1 : 0;
+ return (keep_private_thread) ? 1 : 0;
}