From: Mike McCormack <mj.mccormack@samsung.com>

Subject: ecore-glib integration patches

0001-Make-gmain-integration-work.path applies to the enlightenment SVN.

(in svn with some formatting fixes applied).



SVN revision: 53135
This commit is contained in:
Mike McCormack 2010-10-07 07:23:26 +00:00 committed by Carsten Haitzler
parent 00a661beae
commit b34b4c2359
1 changed files with 130 additions and 68 deletions

View File

@ -74,6 +74,9 @@ struct _Ecore_Fd_Handler
Eina_Bool write_active : 1;
Eina_Bool error_active : 1;
Eina_Bool delete_me : 1;
#if defined(USE_G_MAIN_LOOP) && !defined(HAVE_EPOLL)
GPollFD gfd;
#endif
};
#ifdef _WIN32
@ -130,19 +133,20 @@ static double t2 = 0.0;
#ifdef HAVE_EPOLL
static int epoll_fd = -1;
static GPollFD ecore_epoll_fd;
#endif
#ifdef USE_G_MAIN_LOOP
static GSource *ecore_epoll_source;
static GPollFD ecore_epoll_fd;
static guint ecore_epoll_id;
static GSource *ecore_glib_source;
static guint ecore_glib_source_id;
static GMainLoop* ecore_main_loop;
static gboolean ecore_idling;
static gboolean ecore_fds_ready;
#endif
#ifdef HAVE_EPOLL
static inline int _ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
static inline int
_ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
{
int events = 0;
if (fdh->flags & ECORE_FD_READ) events |= EPOLLIN;
@ -151,16 +155,30 @@ static inline int _ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
return events;
}
#else
static inline int _ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh __UNUSED__)
static inline int
_ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh __UNUSED__)
{
return 0;
}
#endif
#ifdef HAVE_EPOLL
static inline int _ecore_main_fdh_epoll_add(Ecore_Fd_Handler *fdh)
#ifdef USE_G_MAIN_LOOP
static inline int
_gfd_events_from_fdh(Ecore_Fd_Handler *fdh)
{
int events = 0;
if (fdh->flags & ECORE_FD_READ) events |= G_IO_IN;
if (fdh->flags & ECORE_FD_WRITE) events |= G_IO_OUT;
if (fdh->flags & ECORE_FD_ERROR) events |= G_IO_ERR;
return events;
}
#endif
static inline int
_ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
{
int r = 0;
#ifdef HAVE_EPOLL
struct epoll_event ev;
memset(&ev, 0, sizeof (ev));
@ -168,18 +186,26 @@ static inline int _ecore_main_fdh_epoll_add(Ecore_Fd_Handler *fdh)
ev.data.ptr = fdh;
INF("adding poll on %d %08x", fdh->fd, ev.events);
r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fdh->fd, &ev);
return r;
}
#elif USE_G_MAIN_LOOP
fdh->gfd.fd = fdh->fd;
fdh->gfd.events = _gfd_events_from_fdh(fdh);
fdh->gfd.revents = 0;
INF("adding gpoll on %d %08x", fdh->fd, fdh->gfd.events);
g_source_add_poll(ecore_glib_source, &fdh->gfd);
#else
static inline int _ecore_main_fdh_epoll_add(Ecore_Fd_Handler *fdh __UNUSED__)
if (!ECORE_MAGIC_CHECK(fdh, ECORE_MAGIC_FD_HANDLER))
{
return 0;
ECORE_MAGIC_FAIL(fdh, ECORE_MAGIC_FD_HANDLER,
"_ecore_main_fdh_poll_add");
}
#endif
return r;
}
#ifdef HAVE_EPOLL
static inline void _ecore_main_fdh_epoll_del(Ecore_Fd_Handler *fdh)
static inline void
_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh)
{
#ifdef HAVE_EPOLL
struct epoll_event ev;
memset(&ev, 0, sizeof (ev));
@ -190,17 +216,26 @@ static inline void _ecore_main_fdh_epoll_del(Ecore_Fd_Handler *fdh)
{
ERR("Failed to delete epoll fd %d! (errno=%d)", fdh->fd, errno);
}
}
#elif USE_G_MAIN_LOOP
fdh->gfd.fd = fdh->fd;
fdh->gfd.events = _gfd_events_from_fdh(fdh);
fdh->gfd.revents = 0;
INF("adding gpoll on %d %08x", fdh->fd, fdh->gfd.events);
g_source_add_poll(ecore_glib_source, &fdh->gfd);
#else
static inline void _ecore_main_fdh_epoll_del(Ecore_Fd_Handler *fdh __UNUSED__)
if (!ECORE_MAGIC_CHECK(fdh, ECORE_MAGIC_FD_HANDLER))
{
ECORE_MAGIC_FAIL(fdh, ECORE_MAGIC_FD_HANDLER,
"_ecore_main_fdh_poll_del");
}
#endif
}
#ifdef HAVE_EPOLL
static inline int _ecore_main_fdh_epoll_modify(Ecore_Fd_Handler *fdh)
static inline int
_ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
{
int r = 0;
#ifdef HAVE_EPOLL
struct epoll_event ev;
memset(&ev, 0, sizeof (ev));
@ -208,17 +243,23 @@ static inline int _ecore_main_fdh_epoll_modify(Ecore_Fd_Handler *fdh)
ev.data.ptr = fdh;
INF("modifing epoll on %d to %08x", fdh->fd, ev.events);
r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fdh->fd, &ev);
return r;
}
#elif USE_G_MAIN_LOOP
fdh->gfd.fd = fdh->fd;
fdh->gfd.events = _gfd_events_from_fdh(fdh);
fdh->gfd.revents = 0;
INF("modifing gpoll on %d to %08x", fdh->fd, fdh->gfd.events);
#else
static inline int _ecore_main_fdh_epoll_modify(Ecore_Fd_Handler *fdh __UNUSED__)
if (!ECORE_MAGIC_CHECK(fdh, ECORE_MAGIC_FD_HANDLER))
{
return 0;
ECORE_MAGIC_FAIL(fdh, ECORE_MAGIC_FD_HANDLER,
"_ecore_main_fdh_poll_modify");
}
#endif
return r;
}
#ifdef HAVE_EPOLL
static inline int _ecore_main_fdh_epoll_mark_active(void)
static inline int _ecore_main_fdh_poll_mark_active(void)
{
struct epoll_event ev[32];
int i, ret;
@ -240,7 +281,7 @@ static inline int _ecore_main_fdh_epoll_mark_active(void)
if (!ECORE_MAGIC_CHECK(fdh, ECORE_MAGIC_FD_HANDLER))
{
ECORE_MAGIC_FAIL(fdh, ECORE_MAGIC_FD_HANDLER,
"_ecore_main_fdh_epoll_mark_active");
"_ecore_main_fdh_poll_mark_active");
continue;
}
if (fdh->delete_me)
@ -248,12 +289,9 @@ static inline int _ecore_main_fdh_epoll_mark_active(void)
ERR("deleted fd in epoll");
continue;
}
if (ev->events & EPOLLIN)
fdh->read_active = 1;
if (ev->events & EPOLLOUT)
fdh->write_active = 1;
if (ev->events & EPOLLERR)
fdh->error_active = 1;
if (ev->events & EPOLLIN) fdh->read_active = 1;
if (ev->events & EPOLLOUT) fdh->write_active = 1;
if (ev->events & EPOLLERR) fdh->error_active = 1;
}
return ret;
@ -262,6 +300,28 @@ static inline int _ecore_main_fdh_epoll_mark_active(void)
#ifdef USE_G_MAIN_LOOP
static inline int _ecore_main_fdh_poll_mark_active(void)
{
Ecore_Fd_Handler *fdh;
int ret = 0;
/* call the prepare callback for all handlers */
EINA_INLIST_FOREACH(fd_handlers, fdh)
{
if (fdh->delete_me)
continue;
if (fdh->gfd.revents & G_IO_IN) fdh->read_active = 1;
if (fdh->gfd.revents & G_IO_OUT) fdh->write_active = 1;
if (fdh->gfd.revents & G_IO_ERR) fdh->error_active = 1;
if (fdh->gfd.revents & (G_IO_IN|G_IO_OUT|G_IO_ERR)) ret++;
}
INF("found %d active fds", ret);
return ret;
}
/* like we are about to enter main_loop_select in _ecore_main_select */
static gboolean
_ecore_main_gsource_prepare(GSource *source, gint *next_time)
@ -315,7 +375,7 @@ _ecore_main_gsource_check(GSource *source)
INF("enter");
in_main_loop++;
ecore_fds_ready = (_ecore_main_fdh_epoll_mark_active() > 0);
ecore_fds_ready = (_ecore_main_fdh_poll_mark_active() > 0);
_ecore_main_fd_handlers_cleanup();
_ecore_time_loop_time = ecore_time_get();
@ -418,17 +478,19 @@ _ecore_main_loop_init(void)
#endif
#ifdef USE_G_MAIN_LOOP
ecore_epoll_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource));
if (!ecore_epoll_source)
ecore_glib_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource));
if (!ecore_glib_source)
CRIT("Failed to create glib source for epoll!");
else
{
#ifdef HAVE_EPOLL
ecore_epoll_fd.fd = epoll_fd;
ecore_epoll_fd.events = G_IO_IN;
ecore_epoll_fd.revents = 0;
g_source_add_poll(ecore_epoll_source, &ecore_epoll_fd);
ecore_epoll_id = g_source_attach(ecore_epoll_source, NULL);
if (ecore_epoll_id <= 0)
g_source_add_poll(ecore_glib_source, &ecore_epoll_fd);
#endif
ecore_glib_source_id = g_source_attach(ecore_glib_source, NULL);
if (ecore_glib_source_id <= 0)
CRIT("Failed to attach glib source to default context");
}
#endif
@ -439,10 +501,10 @@ void
_ecore_main_loop_shutdown(void)
{
#ifdef USE_G_MAIN_LOOP
if (ecore_epoll_source)
if (ecore_glib_source)
{
g_source_destroy(ecore_epoll_source);
ecore_epoll_source = NULL;
g_source_destroy(ecore_glib_source);
ecore_glib_source = NULL;
}
#endif
@ -611,9 +673,9 @@ ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, Ecore_Fd_Cb func
ECORE_MAGIC_SET(fdh, ECORE_MAGIC_FD_HANDLER);
fdh->fd = fd;
fdh->flags = flags;
if (0 > _ecore_main_fdh_epoll_add(fdh))
if (_ecore_main_fdh_poll_add(fdh) < 0)
{
ERR("Failed to add epoll fd %d (errno = %d)!", fd, errno);
ERR("Failed to add poll on fd %d (errno = %d)!", fd, errno);
free(fdh);
return NULL;
}
@ -683,7 +745,7 @@ ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler)
}
fd_handler->delete_me = 1;
fd_handlers_delete_me = 1;
_ecore_main_fdh_epoll_del(fd_handler);
_ecore_main_fdh_poll_del(fd_handler);
return fd_handler->data;
}
@ -782,7 +844,7 @@ ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_
return;
}
fd_handler->flags = flags;
if (0 > _ecore_main_fdh_epoll_modify(fd_handler))
if (_ecore_main_fdh_poll_modify(fd_handler) < 0)
{
ERR("Failed to mod epoll fd %d!", fd_handler->fd);
}
@ -927,7 +989,7 @@ _ecore_main_select(double timeout)
if (ret > 0)
{
#ifdef HAVE_EPOLL
_ecore_main_fdh_epoll_mark_active();
_ecore_main_fdh_poll_mark_active();
#else /* HAVE_EPOLL */
Ecore_Fd_Handler *fdh;