tpl_bool_t is_eventfd;
tpl_gsource_functions *gsource_funcs;
- tpl_bool_t is_disposable;
+ tpl_gsource_type_t type;
void *data;
};
gsource, gsource->fd, cond);
}
- if (gsource->is_disposable)
+ if (gsource->type == SOURCE_TYPE_DISPOSABLE)
ret = TPL_GSOURCE_REMOVE;
return ret;
tpl_gsource *
tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
- tpl_gsource_functions *funcs, tpl_bool_t is_disposable)
+ tpl_gsource_functions *funcs, tpl_gsource_type_t type)
{
tpl_gsource *new_gsource = NULL;
new_gsource->is_eventfd = TPL_TRUE;
} else {
new_gsource->fd = fd;
+ new_gsource->is_eventfd = TPL_FALSE;
}
new_gsource->thread = thread;
new_gsource->gsource_funcs = funcs;
new_gsource->data = data;
- new_gsource->is_disposable = is_disposable;
+ new_gsource->type = type;
new_gsource->tag = g_source_add_unix_fd(&new_gsource->gsource,
new_gsource->fd,
typedef GMutex tpl_gmutex;
typedef GCond tpl_gcond;
+typedef enum {
+ SOURCE_TYPE_UNKNOWN = -1, /* not specified. it will be classified to NORMAL */
+ SOURCE_TYPE_NORMAL, /* normal source */
+ SOURCE_TYPE_DISPOSABLE, /* disposable source */
+ SOURCE_TYPE_FINALIZER, /* disposable source to finalize normal source. */
+ SOURCE_TYPE_MAX
+} tpl_gsource_type_t;
+
struct _tpl_gsource_functions {
tpl_bool_t (*prepare) (tpl_gsource *source);
tpl_bool_t (*check) (tpl_gsource *source);
* If it is -1, eventfd is created in this function.
* @param funcs Pointer to tpl_gsource_functions.
* This structure corresponds to GSourceFuncs, and dispatch and finalize are required.
- * @param is_disposable If it is intended to be used for single use, TRUE should be passed,
- * and FALSE should be passed to keep it.
- * In the case of disposable, it is not necessary to call tpl_gsource_destroy.
+ * @param type Type of source to be created. @see tpl_gsource_type_t
* @return Pointer to newly created tpl_gsource.
*
* All created tpl_gsource resources will be freed in the thread.
*/
tpl_gsource *
tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
- tpl_gsource_functions *funcs, tpl_bool_t is_disposable);
+ tpl_gsource_functions *funcs, tpl_gsource_type_t type);
/**
* Detach the passed tpl_gsource from thread and destroy it.
tdm_source = tpl_gsource_create(wl_egl_display->thread,
(void *)wl_egl_display, tdm_display_fd,
- &tdm_funcs, TPL_FALSE);
+ &tdm_funcs, SOURCE_TYPE_NORMAL);
if (!tdm_source) {
TPL_ERR("Failed to create tdm_gsource\n");
tdm_client_destroy(tdm_client);
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),
- &disp_funcs, TPL_FALSE);
+ &disp_funcs, SOURCE_TYPE_NORMAL);
if (!wl_egl_display->disp_source) {
TPL_ERR("Failed to add native_display(%p) to thread(%p)",
display->native_handle,