tpl_gthread *thread;
int fd;
- tpl_bool_t is_eventfd;
+ fd_type_t fd_type;
tpl_gsource_functions *gsource_funcs;
tpl_gsource_type_t type;
ssize_t s;
uint64_t message = 0;
- if (gsource->is_eventfd) {
+ if (gsource->fd_type == FD_TYPE_EVENT) {
s = read(gsource->fd, &message, sizeof(uint64_t));
if (s != sizeof(uint64_t)) {
TPL_ERR("Failed to read from event_fd(%d)",
if (gsource->gsource_funcs && gsource->gsource_funcs->finalize)
gsource->gsource_funcs->finalize(gsource);
- if (gsource->is_eventfd)
+ if (gsource->fd_type == FD_TYPE_EVENT)
close(gsource->fd);
gsource->fd = -1;
};
tpl_gsource *
-tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
+tpl_gsource_create(tpl_gthread *thread, void *data, int fd, fd_type_t fd_type,
tpl_gsource_functions *funcs, tpl_gsource_type_t type)
{
tpl_gsource *new_gsource = NULL;
return NULL;
}
- new_gsource->is_eventfd = TPL_TRUE;
+ new_gsource->fd_type = FD_TYPE_EVENT;
} else {
new_gsource->fd = fd;
- new_gsource->is_eventfd = TPL_FALSE;
+ new_gsource->fd_type = fd_type;
}
new_gsource->thread = thread;
new_gsource->intended_destroy = TPL_FALSE;
if (new_gsource->type == SOURCE_TYPE_NORMAL) {
- tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1,
+ tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1, FD_TYPE_NONE,
NULL, SOURCE_TYPE_FINALIZER);
new_gsource->finalizer = finalizer;
} else
uint64_t value = message;
int ret;
- if (!source->is_eventfd) {
+ if (source->fd_type != FD_TYPE_EVENT) {
TPL_ERR("source is not using eventfd. source(%p) fd(%d)",
source, source->fd);
return;
typedef GMutex tpl_gmutex;
typedef GCond tpl_gcond;
+typedef enum {
+ FD_TYPE_NONE = -1, /* not specified */
+ FD_TYPE_EVENT, /* event fd. should close it when finalize */
+ FD_TYPE_FENCE, /* fence fd. should close after waiting until it signaled */
+ FD_TYPE_SOCKET, /* socket fd. cannot close this passed fd */
+ FD_TYPE_MAX
+} fd_type_t;
+
typedef enum {
SOURCE_TYPE_UNKNOWN = -1, /* not specified. it will be classified to NORMAL */
SOURCE_TYPE_NORMAL, /* normal source */
* @see tpl_gsource_destroy
*/
tpl_gsource *
-tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
+tpl_gsource_create(tpl_gthread *thread, void *data, int fd, fd_type_t fd_type,
tpl_gsource_functions *funcs, tpl_gsource_type_t type);
/**
wl_egl_display->disp_source = tpl_gsource_create(wl_egl_display->thread,
(void *)wl_egl_display,
wl_display_get_fd(wl_egl_display->wl_display),
+ FD_TYPE_SOCKET,
&disp_funcs, SOURCE_TYPE_NORMAL);
if (!wl_egl_display->disp_source) {
TPL_ERR("Failed to add native_display(%p) to thread(%p)",
wl_egl_display->tdm.tdm_source = tpl_gsource_create(wl_egl_display->thread,
(void *)wl_egl_display,
wl_egl_display->tdm.tdm_display_fd,
+ FD_TYPE_SOCKET,
&tdm_funcs, SOURCE_TYPE_NORMAL);
wl_egl_display->tdm.gsource_finalized = TPL_FALSE;
if (!wl_egl_display->tdm.tdm_source) {
}
surf_source = tpl_gsource_create(wl_egl_display->thread, (void *)wl_egl_surface,
- -1, &surf_funcs, SOURCE_TYPE_NORMAL);
+ -1, FD_TYPE_NONE, &surf_funcs, SOURCE_TYPE_NORMAL);
if (!surf_source) {
TPL_ERR("Failed to create surf_source with wl_egl_surface(%p)",
wl_egl_surface);
wl_egl_buffer->waiting_source =
tpl_gsource_create(wl_egl_display->thread, wl_egl_buffer,
- wl_egl_buffer->acquire_fence_fd, &buffer_funcs,
+ wl_egl_buffer->acquire_fence_fd,
+ FD_TYPE_FENCE, &buffer_funcs,
SOURCE_TYPE_DISPOSABLE);
wl_egl_buffer->status = WAITING_SIGNALED;
wl_vk_display->disp_source = tpl_gsource_create(wl_vk_display->thread,
(void *)wl_vk_display,
+ FD_TYPE_SOCKET,
wl_display_get_fd(wl_vk_display->wl_display),
&disp_funcs, SOURCE_TYPE_NORMAL);
if (!wl_vk_display->disp_source) {
wl_vk_display->tdm.tdm_source = tpl_gsource_create(wl_vk_display->thread,
(void *)wl_vk_display,
wl_vk_display->tdm.tdm_display_fd,
+ FD_TYPE_SOCKET,
&tdm_funcs, SOURCE_TYPE_NORMAL);
if (!wl_vk_display->tdm.tdm_source) {
TPL_ERR("Failed to create tdm_gsource\n");
}
surf_source = tpl_gsource_create(wl_vk_display->thread, (void *)wl_vk_surface,
- -1, &surf_funcs, SOURCE_TYPE_NORMAL);
+ -1, FD_TYPE_NONE, &surf_funcs, SOURCE_TYPE_NORMAL);
if (!surf_source) {
TPL_ERR("Failed to create surf_source with wl_vk_surface(%p)",
wl_vk_surface);