#include "tdm_private.h"
typedef struct _tdm_event_loop_source_base {
+ struct list_head link;
+ tdm_private_display *private_display;
struct wl_event_source *wl_source;
} tdm_event_loop_source_base;
typedef struct _tdm_event_loop_source_fd {
tdm_event_loop_source_base base;
- tdm_private_display *private_display;
tdm_event_loop_fd_handler func;
void *user_data;
} tdm_event_loop_source_fd;
typedef struct _tdm_event_loop_source_timer {
tdm_event_loop_source_base base;
- tdm_private_display *private_display;
tdm_event_loop_timer_handler func;
void *user_data;
} tdm_event_loop_source_timer;
+static tdm_private_loop *keep_private_loop;
+
static tdm_error
_tdm_event_loop_main_fd_handler(int fd, tdm_event_loop_mask mask, void *user_data)
{
return TDM_ERROR_OPERATION_FAILED;
}
+ LIST_INITHEAD(&private_loop->source_list);
+
private_loop->dpy = private_display;
private_display->private_loop = private_loop;
return TDM_ERROR_OPERATION_FAILED;
}
+ keep_private_loop = private_loop;
+
TDM_INFO("event loop fd(%d)", wl_event_loop_get_fd(private_loop->wl_loop));
return TDM_ERROR_NONE;
tdm_event_loop_deinit(tdm_private_display *private_display)
{
tdm_private_module *private_module = NULL;
+ tdm_event_loop_source_base *source = NULL, *ss = NULL;
TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
private_module->fd = -1;
}
- if (private_display->private_loop->wl_display)
- wl_display_destroy(private_display->private_loop->wl_display);
+ LIST_FOR_EACH_ENTRY_SAFE(source, ss, &private_display->private_loop->source_list, link) {
+ tdm_event_loop_source_remove(source);
+ }
+
+ wl_display_destroy(private_display->private_loop->wl_display);
free(private_display->private_loop);
private_display->private_loop = NULL;
+ keep_private_loop = NULL;
+
+ TDM_INFO("event loop deinit done");
}
INTERN void
TDM_RETURN_VAL_IF_FAIL(fd_source, 1);
TDM_RETURN_VAL_IF_FAIL(fd_source->func, 1);
- private_display = fd_source->private_display;
+ private_display = fd_source->base.private_display;
if (wl_mask & WL_EVENT_READABLE)
mask |= TDM_EVENT_LOOP_READABLE;
if (mask & TDM_EVENT_LOOP_WRITABLE)
wl_mask |= WL_EVENT_WRITABLE;
- fd_source->private_display = private_display;
fd_source->func = func;
fd_source->user_data = user_data;
+ fd_source->base.private_display = private_display;
fd_source->base.wl_source =
wl_event_loop_add_fd(private_loop->wl_loop,
fd, wl_mask, _tdm_event_loop_fd_func, fd_source);
return NULL;
}
+ LIST_ADDTAIL(&fd_source->base.link, &private_loop->source_list);
+
if (error)
*error = TDM_ERROR_NONE;
TDM_RETURN_VAL_IF_FAIL(timer_source, 1);
TDM_RETURN_VAL_IF_FAIL(timer_source->func, 1);
- private_display = timer_source->private_display;
+ private_display = timer_source->base.private_display;
/* TDM event_loop function is actually for TDM backend module. When we call the
* backend's functions, we have to lock the mutex. TDM backend shouldn't consider
timer_source = calloc(1, sizeof(tdm_event_loop_source_timer));
TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(timer_source, TDM_ERROR_OUT_OF_MEMORY, NULL);
- timer_source->private_display = private_display;
timer_source->func = func;
timer_source->user_data = user_data;
+ timer_source->base.private_display = private_display;
timer_source->base.wl_source =
wl_event_loop_add_timer(private_loop->wl_loop,
_tdm_event_loop_timer_func, timer_source);
return NULL;
}
+ LIST_ADDTAIL(&timer_source->base.link, &private_loop->source_list);
+
if (error)
*error = TDM_ERROR_NONE;
TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
- if (!base)
+ if (!base || !keep_private_loop)
return;
+ LIST_DEL(&base->link);
+
wl_event_source_remove(base->wl_source);
free(source);