summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-10-26 21:49:16 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-10-26 21:49:16 -0200
commite87215744ad0ac66cc8049b6d3576bd886c93543 (patch)
tree8db8118b34b5098b6621037648f12f4c4015607a
parent989cee0d565c4a55578dc64539ce9c89d3fea0d4 (diff)
-rw-r--r--configure.ac21
-rw-r--r--src/lib/ecore/ecore_main.c524
2 files changed, 500 insertions, 45 deletions
diff --git a/configure.ac b/configure.ac
index 6fba1735a3..3123b76551 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1005,8 +1005,27 @@ EFL_EVAL_PKGS([EINA_CXX])
1005EFL_LIB_END([Eina_Cxx]) 1005EFL_LIB_END([Eina_Cxx])
1006#### End of Eina CXX 1006#### End of Eina CXX
1007 1007
1008#### Eet 1008AC_ARG_WITH([libuv],
1009 [AS_HELP_STRING([--with-libuv=@<:@yes|no@:>@],[add libuv support. @<:@default=yes@:>@])],
1010 [
1011 if test "x${withval}" = "yes" ; then
1012 with_libuv="yes"
1013 else
1014 if test "x${withval}" = "xalways" ; then
1015 with_libuv="always"
1016 else
1017 with_libuv="no"
1018 fi
1019 fi
1020 ],
1021 [with_libuv="yes"])
1009 1022
1023AM_CONDITIONAL([HAVE_LIBUV], [test "x${with_libuv}" = "xyes"])
1024AC_DEFINE_IF([HAVE_LIBUV], [test "x${with_js}" = "xyes"],
1025 [1], [Compiling libuv event loop integration])
1026AC_SUBST([HAVE_LIBUV])
1027
1028#### Eet
1010EFL_LIB_START([Eet]) 1029EFL_LIB_START([Eet])
1011 1030
1012### Default values 1031### Default values
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index de84e61a7f..90735d354e 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -61,7 +61,7 @@
61#include "Ecore.h" 61#include "Ecore.h"
62#include "ecore_private.h" 62#include "ecore_private.h"
63 63
64#ifdef HAVE_SYS_EPOLL_H 64#if defined(HAVE_SYS_EPOLL_H) && !defined(HAVE_LIBUV)
65# define HAVE_EPOLL 1 65# define HAVE_EPOLL 1
66# include <sys/epoll.h> 66# include <sys/epoll.h>
67#else 67#else
@@ -157,6 +157,51 @@ timerfd_settime(int fd EINA_UNUSED,
157# include <glib.h> 157# include <glib.h>
158#endif 158#endif
159 159
160#ifdef HAVE_LIBUV
161#ifdef HAVE_NODE_UV_H
162#include <node/uv.h>
163#elif defined(HAVE_NODEJS_DEPS_UV_UV_H)
164#include <nodejs/deps/uv/uv.h>
165#elif defined(HAVE_NODEJS_DEPS_UV_INCLUDE_UV_H)
166#include <nodejs/deps/uv/include/uv.h>
167#elif defined(HAVE_NODEJS_SRC_UV_H)
168#include <nodejs/src/uv.h>
169#elif defined(HAVE_UV_H)
170#include <uv.h>
171#else
172#error No uv.h header found?
173#endif
174
175#include <dlfcn.h>
176
177static uv_prepare_t _ecore_main_uv_prepare;
178static uv_check_t _ecore_main_uv_check;
179static uv_timer_t _ecore_main_uv_handle_timers;
180static Eina_Bool _ecore_main_uv_idling;
181
182static int (*_dl_uv_loop_alive)(uv_loop_t*) = 0;
183static int (*_dl_uv_run)(uv_loop_t*, uv_run_mode mode) = 0;
184static int (*_dl_uv_stop)(uv_loop_t*) = 0;
185static uv_loop_t* (*_dl_uv_default_loop)() = 0;
186static int (*_dl_uv_poll_init_socket)(uv_loop_t* loop, uv_poll_t* handle, uv_os_sock_t fd) = 0;
187static int (*_dl_uv_poll_init)(uv_loop_t* loop, uv_poll_t* handle, int fd) = 0;
188static int (*_dl_uv_poll_start)(uv_poll_t* handle, int events, uv_poll_cb cb) = 0;
189static int (*_dl_uv_poll_stop)(uv_poll_t* handle) = 0;
190static int (*_dl_uv_timer_init)(uv_loop_t*, uv_timer_t* handle);
191static int (*_dl_uv_timer_start)(uv_timer_t* handle,
192 uv_timer_cb cb,
193 uint64_t timeout,
194 uint64_t repeat);
195static int (*_dl_uv_timer_stop)(uv_timer_t* handle);
196static int (*_dl_uv_prepare_init)(uv_loop_t*, uv_prepare_t* prepare);
197static int (*_dl_uv_prepare_start)(uv_prepare_t* prepare, uv_prepare_cb cb);
198static int (*_dl_uv_prepare_stop)(uv_prepare_t* prepare);
199static int (*_dl_uv_check_init)(uv_loop_t*, uv_check_t* prepare);
200static int (*_dl_uv_check_start)(uv_check_t* prepare, uv_check_cb cb);
201static int (*_dl_uv_check_stop)(uv_check_t* prepare);
202static int (*_dl_uv_close)(uv_handle_t* handle, uv_close_cb close_cb);
203#endif
204
160#define NS_PER_SEC (1000.0 * 1000.0 * 1000.0) 205#define NS_PER_SEC (1000.0 * 1000.0 * 1000.0)
161 206
162struct _Ecore_Fd_Handler 207struct _Ecore_Fd_Handler
@@ -181,6 +226,9 @@ struct _Ecore_Fd_Handler
181#if defined(USE_G_MAIN_LOOP) 226#if defined(USE_G_MAIN_LOOP)
182 GPollFD gfd; 227 GPollFD gfd;
183#endif 228#endif
229#ifdef HAVE_LIBUV
230 uv_poll_t uv_handle;
231#endif
184}; 232};
185GENERIC_ALLOC_SIZE_DECLARE(Ecore_Fd_Handler); 233GENERIC_ALLOC_SIZE_DECLARE(Ecore_Fd_Handler);
186 234
@@ -198,7 +246,7 @@ struct _Ecore_Win32_Handler
198GENERIC_ALLOC_SIZE_DECLARE(Ecore_Win32_Handler); 246GENERIC_ALLOC_SIZE_DECLARE(Ecore_Win32_Handler);
199#endif 247#endif
200 248
201#ifndef USE_G_MAIN_LOOP 249#if !defined(USE_G_MAIN_LOOP) && !defined(HAVE_LIBUV)
202static int _ecore_main_select(double timeout); 250static int _ecore_main_select(double timeout);
203#endif 251#endif
204static void _ecore_main_prepare_handlers(void); 252static void _ecore_main_prepare_handlers(void);
@@ -310,9 +358,13 @@ _ecore_try_add_to_call_list(Ecore_Fd_Handler *fdh)
310{ 358{
311 /* check if this fdh is already in the list */ 359 /* check if this fdh is already in the list */
312 if (fdh->next_ready) 360 if (fdh->next_ready)
313 return; 361 {
362 DBG("next_ready");
363 return;
364 }
314 if (fdh->read_active || fdh->write_active || fdh->error_active) 365 if (fdh->read_active || fdh->write_active || fdh->error_active)
315 { 366 {
367 DBG("added");
316 /* 368 /*
317 * make sure next_ready is non-null by pointing to ourselves 369 * make sure next_ready is non-null by pointing to ourselves
318 * use that to indicate this fdh is in the ready list 370 * use that to indicate this fdh is in the ready list
@@ -375,97 +427,195 @@ _gfd_events_from_fdh(Ecore_Fd_Handler *fdh)
375} 427}
376#endif 428#endif
377 429
430#ifdef HAVE_LIBUV
431static void
432_ecore_main_uv_poll_cb(uv_poll_t* handle, int status, int events)
433{
434 DBG("_ecore_main_uv_poll_cb %p status %d events %d", (void*)handle->data, status, events);
435 Ecore_Fd_Handler* fdh = handle->data;
436
437 if(_ecore_main_uv_idling)
438 {
439 DBG("not IDLE anymore");
440 _ecore_main_uv_idling = EINA_FALSE;
441 _ecore_idle_exiter_call();
442 _ecore_animator_run_reset();
443 }
444
445 if (status)
446 fdh->error_active = EINA_TRUE;
447 if (events & UV_READABLE)
448 fdh->read_active = EINA_TRUE;
449 if (events & UV_WRITABLE)
450 fdh->write_active = EINA_TRUE;
451
452 _ecore_try_add_to_call_list(fdh);
453
454 _ecore_main_fd_handlers_call();
455 if (fd_handlers_with_buffer)
456 _ecore_main_fd_handlers_buf_call();
457 _ecore_signal_received_process();
458 _ecore_event_call();
459 _ecore_main_fd_handlers_cleanup();
460 _ecore_timer_expired_timers_call(_ecore_time_loop_time);
461 _ecore_timer_cleanup();
462}
463
464static int
465_ecore_main_uv_events_from_fdh(Ecore_Fd_Handler *fdh)
466{
467 int events = 0;
468 if (fdh->flags & ECORE_FD_READ) events |= UV_READABLE;
469 if (fdh->flags & ECORE_FD_WRITE) events |= UV_WRITABLE;
470 DBG("events is %d", (int)events);
471 return events;
472}
473#endif
474
378static inline int 475static inline int
379_ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh) 476_ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
380{ 477{
478 DBG("_ecore_main_fdh_poll_add");
381 int r = 0; 479 int r = 0;
382 480
383 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 481#ifdef HAVE_LIBUV
482 if(!_dl_uv_run)
483#endif
384 { 484 {
385 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd, 485 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
386 _ecore_poll_events_from_fdh(fdh), fdh); 486 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd,
487 _ecore_poll_events_from_fdh(fdh), fdh);
387 } 488 }
388#ifdef USE_G_MAIN_LOOP 489#ifdef HAVE_LIBUV
389 else 490 else
491#endif
390 { 492 {
493#ifdef HAVE_LIBUV
494 if(!fdh->file)
495 {
496 DBG("_ecore_main_fdh_poll_add libuv socket %p", fdh);
497 fdh->uv_handle.data = fdh;
498 DBG("_ecore_main_fdh_poll_add2 %p", fdh);
499 _dl_uv_poll_init_socket(_dl_uv_default_loop(), &fdh->uv_handle, fdh->fd);
500 DBG("_ecore_main_fdh_poll_add3 %p", fdh->uv_handle.data);
501 _dl_uv_poll_start(&fdh->uv_handle, _ecore_main_uv_events_from_fdh(fdh)
502 , _ecore_main_uv_poll_cb);
503 DBG("_ecore_main_fdh_poll_add libuv DONE");
504 }
505 else
506 {
507 DBG("_ecore_main_fdh_poll_add libuv file");
508 fdh->uv_handle.data = fdh;
509 DBG("_ecore_main_fdh_poll_add2 %p", fdh);
510 _dl_uv_poll_init(_dl_uv_default_loop(), &fdh->uv_handle, fdh->fd);
511 DBG("_ecore_main_fdh_poll_add3 %p", fdh->uv_handle.data);
512 _dl_uv_poll_start(&fdh->uv_handle, _ecore_main_uv_events_from_fdh(fdh)
513 , _ecore_main_uv_poll_cb);
514 DBG("_ecore_main_fdh_poll_add libuv DONE");
515 }
516#elif defined(USE_G_MAIN_LOOP)
391 fdh->gfd.fd = fdh->fd; 517 fdh->gfd.fd = fdh->fd;
392 fdh->gfd.events = _gfd_events_from_fdh(fdh); 518 fdh->gfd.events = _gfd_events_from_fdh(fdh);
393 fdh->gfd.revents = 0; 519 fdh->gfd.revents = 0;
394 DBG("adding gpoll on %d %08x", fdh->fd, fdh->gfd.events); 520 DBG("adding gpoll on %d %08x", fdh->fd, fdh->gfd.events);
395 g_source_add_poll(ecore_glib_source, &fdh->gfd); 521 g_source_add_poll(ecore_glib_source, &fdh->gfd);
396 }
397#endif 522#endif
523 }
398 return r; 524 return r;
399} 525}
400 526
401static inline void 527static inline void
402_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh) 528_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh)
403{ 529{
404 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 530#ifdef HAVE_LIBUV
531 if(!_dl_uv_run)
532#endif
405 { 533 {
406 struct epoll_event ev; 534 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
407 int efd = _ecore_get_epoll_fd(); 535 {
408 536 struct epoll_event ev;
409 memset(&ev, 0, sizeof (ev)); 537 int efd = _ecore_get_epoll_fd();
410 DBG("removing poll on %d", fdh->fd); 538
411 /* could get an EBADF if somebody closed the FD before removing it */ 539 memset(&ev, 0, sizeof (ev));
412 if ((epoll_ctl(efd, EPOLL_CTL_DEL, fdh->fd, &ev) < 0)) 540 DBG("removing poll on %d", fdh->fd);
413 { 541 /* could get an EBADF if somebody closed the FD before removing it */
414 if (errno == EBADF) 542 if ((epoll_ctl(efd, EPOLL_CTL_DEL, fdh->fd, &ev) < 0))
415 { 543 {
416 WRN("fd %d was closed, can't remove from epoll - reinit!", 544 if (errno == EBADF)
417 fdh->fd); 545 {
418 _ecore_main_loop_shutdown(); 546 WRN("fd %d was closed, can't remove from epoll - reinit!",
419 _ecore_main_loop_init(); 547 fdh->fd);
420 } 548 _ecore_main_loop_shutdown();
421 else 549 _ecore_main_loop_init();
422 { 550 }
423 ERR("Failed to delete epoll fd %d! (errno=%d)", fdh->fd, errno); 551 else
424 } 552 {
425 } 553 ERR("Failed to delete epoll fd %d! (errno=%d)", fdh->fd, errno);
426 } 554 }
427#ifdef USE_G_MAIN_LOOP 555 }
556 }
557 }
558#ifdef HAVE_LIBUV
428 else 559 else
560#endif
429 { 561 {
562#ifdef HAVE_LIBUV
563 DBG("_ecore_main_fdh_poll_del libuv %p", fdh);
564 uv_handle_t* h = (uv_handle_t*)&fdh->uv_handle;
565 _dl_uv_close(h, 0);
566 DBG("_ecore_main_fdh_poll_del libuv DONE");
567#elif USE_G_MAIN_LOOP
430 fdh->gfd.fd = fdh->fd; 568 fdh->gfd.fd = fdh->fd;
431 fdh->gfd.events = _gfd_events_from_fdh(fdh); 569 fdh->gfd.events = _gfd_events_from_fdh(fdh);
432 fdh->gfd.revents = 0; 570 fdh->gfd.revents = 0;
433 DBG("removing gpoll on %d %08x", fdh->fd, fdh->gfd.events); 571 DBG("removing gpoll on %d %08x", fdh->fd, fdh->gfd.events);
434 g_source_remove_poll(ecore_glib_source, &fdh->gfd); 572 g_source_remove_poll(ecore_glib_source, &fdh->gfd);
435 }
436#endif 573#endif
574 }
437} 575}
438 576
439static inline int 577static inline int
440_ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh) 578_ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
441{ 579{
580 DBG("_ecore_main_fdh_poll_modify %p", fdh);
442 int r = 0; 581 int r = 0;
443 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 582#ifdef HAVE_LIBUV
583 if(!_dl_uv_run)
584#endif
444 { 585 {
445 struct epoll_event ev; 586 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
446 int efd = _ecore_get_epoll_fd(); 587 {
588 struct epoll_event ev;
589 int efd = _ecore_get_epoll_fd();
447 590
448 memset(&ev, 0, sizeof (ev)); 591 memset(&ev, 0, sizeof (ev));
449 ev.events = _ecore_poll_events_from_fdh(fdh); 592 ev.events = _ecore_poll_events_from_fdh(fdh);
450 ev.data.ptr = fdh; 593 ev.data.ptr = fdh;
451 DBG("modifing epoll on %d to %08x", fdh->fd, ev.events); 594 DBG("modifing epoll on %d to %08x", fdh->fd, ev.events);
452 r = epoll_ctl(efd, EPOLL_CTL_MOD, fdh->fd, &ev); 595 r = epoll_ctl(efd, EPOLL_CTL_MOD, fdh->fd, &ev);
596 }
453 } 597 }
454#ifdef USE_G_MAIN_LOOP 598#ifdef HAVE_LIBUV
455 else 599 else
600#endif
456 { 601 {
602#ifdef HAVE_LIBUV
603 _dl_uv_poll_start(&fdh->uv_handle, _ecore_main_uv_events_from_fdh(fdh)
604 , _ecore_main_uv_poll_cb);
605#elif defined(USE_G_MAIN_LOOP)
457 fdh->gfd.fd = fdh->fd; 606 fdh->gfd.fd = fdh->fd;
458 fdh->gfd.events = _gfd_events_from_fdh(fdh); 607 fdh->gfd.events = _gfd_events_from_fdh(fdh);
459 fdh->gfd.revents = 0; 608 fdh->gfd.revents = 0;
460 DBG("modifing gpoll on %d to %08x", fdh->fd, fdh->gfd.events); 609 DBG("modifing gpoll on %d to %08x", fdh->fd, fdh->gfd.events);
461 }
462#endif 610#endif
611 }
463 return r; 612 return r;
464} 613}
465 614
466static inline int 615static inline int
467_ecore_main_fdh_epoll_mark_active(void) 616_ecore_main_fdh_epoll_mark_active(void)
468{ 617{
618 DBG("_ecore_main_fdh_epoll_mark_active");
469 struct epoll_event ev[32]; 619 struct epoll_event ev[32];
470 int i, ret; 620 int i, ret;
471 int efd = _ecore_get_epoll_fd(); 621 int efd = _ecore_get_epoll_fd();
@@ -832,9 +982,62 @@ detect_time_changes_stop(void)
832#endif 982#endif
833} 983}
834 984
985
986#ifdef HAVE_LIBUV
987static inline
988void
989_ecore_main_loop_uv_check(uv_check_t* handle EINA_UNUSED);
990static void _ecore_main_loop_uv_prepare(uv_prepare_t* handle);
991
992static
993void _ecore_main_loop_timer_run(uv_timer_t* timer EINA_UNUSED)
994{
995 if(_ecore_main_uv_idling)
996 {
997 _ecore_main_uv_idling = EINA_FALSE;
998 _ecore_idle_exiter_call();
999 _ecore_animator_run_reset();
1000 }
1001 _ecore_time_loop_time = ecore_time_get();
1002 _ecore_main_loop_uv_check(NULL);
1003
1004 _ecore_main_loop_uv_prepare(NULL);
1005}
1006static void _ecore_main_loop_uv_prepare(uv_prepare_t* handle);
1007
1008static inline
1009void
1010_ecore_main_loop_uv_check(uv_check_t* handle EINA_UNUSED)
1011{
1012 DBG("_ecore_main_loop_uv_check idling? %d", (int)_ecore_main_uv_idling);
1013 in_main_loop++;
1014 _ecore_lock();
1015
1016 if(do_quit)
1017 goto quit;
1018
1019 do
1020 {
1021 _ecore_main_fd_handlers_call();
1022 if (fd_handlers_with_buffer)
1023 _ecore_main_fd_handlers_buf_call();
1024 _ecore_signal_received_process();
1025 _ecore_event_call();
1026 _ecore_main_fd_handlers_cleanup();
1027 _ecore_timer_expired_timers_call(_ecore_time_loop_time);
1028 _ecore_timer_cleanup();
1029 }
1030 while(fd_handlers_to_call);
1031quit:
1032 in_main_loop--;
1033 _ecore_unlock();
1034}
1035#endif
1036
835void 1037void
836_ecore_main_loop_init(void) 1038_ecore_main_loop_init(void)
837{ 1039{
1040 DBG("_ecore_main_loop_init");
838 epoll_fd = epoll_create(1); 1041 epoll_fd = epoll_create(1);
839 if ((epoll_fd < 0) && HAVE_EPOLL) 1042 if ((epoll_fd < 0) && HAVE_EPOLL)
840 WRN("Failed to create epoll fd!"); 1043 WRN("Failed to create epoll fd!");
@@ -851,7 +1054,77 @@ _ecore_main_loop_init(void)
851 _ecore_poll_events_from_fdh(fdh), fdh); 1054 _ecore_poll_events_from_fdh(fdh), fdh);
852 _ecore_main_fdh_poll_add(fdh); 1055 _ecore_main_fdh_poll_add(fdh);
853 } 1056 }
1057#ifdef HAVE_LIBUV
1058 {
1059 DBG("loading lib uv");
1060#ifdef HAVE_NODEJS
1061 void* lib = dlopen(NULL, RTLD_LAZY);
1062#else
1063 void* lib = dlopen("libuv.so", RTLD_GLOBAL | RTLD_LAZY);
1064#endif
854 1065
1066 if(lib && dlsym(lib, "uv_run"))
1067 {
1068 DBG("loaded lib uv");
1069 _dl_uv_run = dlsym(lib, "uv_run");
1070 assert(!!_dl_uv_run);
1071 _dl_uv_stop = dlsym(lib, "uv_stop");
1072 assert(!!_dl_uv_stop);
1073 _dl_uv_default_loop = dlsym(lib, "uv_default_loop");
1074 assert(!!_dl_uv_default_loop);
1075 _dl_uv_poll_init_socket = dlsym(lib, "uv_poll_init_socket");
1076 assert(!!_dl_uv_poll_init_socket);
1077 _dl_uv_poll_init = dlsym(lib, "uv_poll_init");
1078 assert(!!_dl_uv_poll_init);
1079 _dl_uv_poll_start = dlsym(lib, "uv_poll_start");
1080 assert(!!_dl_uv_poll_start);
1081 _dl_uv_poll_stop = dlsym(lib, "uv_poll_stop");
1082 assert(!!_dl_uv_poll_stop);
1083 _dl_uv_timer_init = dlsym(lib, "uv_timer_init");
1084 assert(!!_dl_uv_timer_init);
1085 _dl_uv_timer_start = dlsym(lib, "uv_timer_start");
1086 assert(!!_dl_uv_timer_start);
1087 _dl_uv_timer_stop = dlsym(lib, "uv_timer_stop");
1088 assert(!!_dl_uv_timer_stop);
1089 _dl_uv_prepare_init = dlsym(lib, "uv_prepare_init");
1090 assert(!!_dl_uv_prepare_init);
1091 _dl_uv_prepare_start = dlsym(lib, "uv_prepare_start");
1092 assert(!!_dl_uv_prepare_start);
1093 _dl_uv_prepare_stop = dlsym(lib, "uv_prepare_stop");
1094 assert(!!_dl_uv_prepare_stop);
1095 _dl_uv_check_init = dlsym(lib, "uv_check_init");
1096 assert(!!_dl_uv_check_init);
1097 _dl_uv_check_start = dlsym(lib, "uv_check_start");
1098 assert(!!_dl_uv_check_start);
1099 _dl_uv_check_stop = dlsym(lib, "uv_check_stop");
1100 assert(!!_dl_uv_check_stop);
1101 _dl_uv_close = dlsym(lib, "uv_close");
1102 assert(!!_dl_uv_close);
1103 _dl_uv_loop_alive = dlsym(lib, "uv_loop_alive");
1104 assert(!!_dl_uv_loop_alive);
1105
1106 //dlclose(lib);
1107
1108 DBG("_dl_uv_prepare_init");
1109 _dl_uv_prepare_init(_dl_uv_default_loop(), &_ecore_main_uv_prepare);
1110 DBG("_dl_uv_prepare_start");
1111 _dl_uv_prepare_start(&_ecore_main_uv_prepare, &_ecore_main_loop_uv_prepare);
1112 DBG("_dl_uv_prepare_started");
1113
1114 DBG("_dl_uv_check_init");
1115 _dl_uv_check_init(_dl_uv_default_loop(), &_ecore_main_uv_check);
1116 DBG("_dl_uv_check_start");
1117 _dl_uv_check_start(&_ecore_main_uv_check, &_ecore_main_loop_uv_check);
1118 DBG("_dl_uv_check_started");
1119
1120 _dl_uv_timer_init(_dl_uv_default_loop(), &_ecore_main_uv_handle_timers);
1121 }
1122 /* else */
1123 /* DBG("did not load uv"); */
1124 DBG("loaded dlsyms uv");
1125 }
1126#endif
1127
855 /* setup for the g_main_loop only integration */ 1128 /* setup for the g_main_loop only integration */
856#ifdef USE_G_MAIN_LOOP 1129#ifdef USE_G_MAIN_LOOP
857 ecore_glib_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource)); 1130 ecore_glib_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource));
@@ -916,11 +1189,21 @@ _ecore_main_loop_shutdown(void)
916 close(timer_fd); 1189 close(timer_fd);
917 timer_fd = -1; 1190 timer_fd = -1;
918 } 1191 }
1192
1193#ifdef HAVE_LIBUV
1194 if(_dl_uv_run)
1195 {
1196 DBG("_ecore_main_loop_shutdown");
1197 _dl_uv_timer_stop(&_ecore_main_uv_handle_timers);
1198 _dl_uv_close((uv_handle_t*)&_ecore_main_uv_handle_timers, 0);
1199 }
1200#endif
919} 1201}
920 1202
921void * 1203void *
922_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler) 1204_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler)
923{ 1205{
1206 DBG("_ecore_main_fd_handler_del %p", fd_handler);
924 if (fd_handler->delete_me) 1207 if (fd_handler->delete_me)
925 { 1208 {
926 ERR("fdh %p deleted twice", fd_handler); 1209 ERR("fdh %p deleted twice", fd_handler);
@@ -941,6 +1224,9 @@ EAPI void
941ecore_main_loop_iterate(void) 1224ecore_main_loop_iterate(void)
942{ 1225{
943 EINA_MAIN_LOOP_CHECK_RETURN; 1226 EINA_MAIN_LOOP_CHECK_RETURN;
1227#ifdef HAVE_LIBUV
1228 if(!_dl_uv_run) {
1229#endif
944#ifndef USE_G_MAIN_LOOP 1230#ifndef USE_G_MAIN_LOOP
945 _ecore_lock(); 1231 _ecore_lock();
946 _ecore_time_loop_time = ecore_time_get(); 1232 _ecore_time_loop_time = ecore_time_get();
@@ -949,12 +1235,20 @@ ecore_main_loop_iterate(void)
949#else 1235#else
950 g_main_context_iteration(NULL, 0); 1236 g_main_context_iteration(NULL, 0);
951#endif 1237#endif
1238#ifdef HAVE_LIBUV
1239 }
1240 else
1241 _dl_uv_run(_dl_uv_default_loop(), UV_RUN_ONCE | UV_RUN_NOWAIT);
1242#endif
952} 1243}
953 1244
954EAPI int 1245EAPI int
955ecore_main_loop_iterate_may_block(int may_block) 1246ecore_main_loop_iterate_may_block(int may_block)
956{ 1247{
957 EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); 1248 EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
1249#ifdef HAVE_LIBUV
1250 if(!_dl_uv_run) {
1251#endif
958#ifndef USE_G_MAIN_LOOP 1252#ifndef USE_G_MAIN_LOOP
959 _ecore_lock(); 1253 _ecore_lock();
960 _ecore_time_loop_time = ecore_time_get(); 1254 _ecore_time_loop_time = ecore_time_get();
@@ -966,15 +1260,25 @@ in_main_loop--;
966#else 1260#else
967 return g_main_context_iteration(NULL, may_block); 1261 return g_main_context_iteration(NULL, may_block);
968#endif 1262#endif
1263#ifdef HAVE_LIBUV
1264 }
1265 else
1266 _dl_uv_run(_dl_uv_default_loop(), may_block ? UV_RUN_ONCE | UV_RUN_NOWAIT : UV_RUN_ONCE);
1267#endif
1268 return 0;
969} 1269}
970 1270
971EAPI void 1271EAPI void
972ecore_main_loop_begin(void) 1272ecore_main_loop_begin(void)
973{ 1273{
1274 DBG("ecore_main_loop_begin");
974 EINA_MAIN_LOOP_CHECK_RETURN; 1275 EINA_MAIN_LOOP_CHECK_RETURN;
975#ifdef HAVE_SYSTEMD 1276#ifdef HAVE_SYSTEMD
976 sd_notify(0, "READY=1"); 1277 sd_notify(0, "READY=1");
977#endif 1278#endif
1279#ifdef HAVE_LIBUV
1280 if(!_dl_uv_run) {
1281#endif
978#ifndef USE_G_MAIN_LOOP 1282#ifndef USE_G_MAIN_LOOP
979 _ecore_lock(); 1283 _ecore_lock();
980 in_main_loop++; 1284 in_main_loop++;
@@ -992,6 +1296,20 @@ ecore_main_loop_begin(void)
992 } 1296 }
993 do_quit = 0; 1297 do_quit = 0;
994#endif 1298#endif
1299#ifdef HAVE_LIBUV
1300 }
1301 else
1302 {
1303 DBG("uv_run");
1304 _ecore_time_loop_time = ecore_time_get();
1305 in_main_loop++;
1306 while(!do_quit)
1307 _dl_uv_run(_dl_uv_default_loop(), UV_RUN_DEFAULT);
1308 in_main_loop--;
1309 do_quit = 0;
1310 DBG("quit");
1311 }
1312#endif
995} 1313}
996 1314
997EAPI void 1315EAPI void
@@ -1002,6 +1320,9 @@ ecore_main_loop_quit(void)
1002#ifdef USE_G_MAIN_LOOP 1320#ifdef USE_G_MAIN_LOOP
1003 if (ecore_main_loop) 1321 if (ecore_main_loop)
1004 g_main_loop_quit(ecore_main_loop); 1322 g_main_loop_quit(ecore_main_loop);
1323#elif defined(HAVE_LIBUV)
1324 if (_dl_uv_run)
1325 _dl_uv_stop(_dl_uv_default_loop());
1005#endif 1326#endif
1006} 1327}
1007 1328
@@ -1014,6 +1335,7 @@ ecore_main_loop_nested_get(void)
1014EAPI Eina_Bool 1335EAPI Eina_Bool
1015ecore_main_loop_animator_ticked_get(void) 1336ecore_main_loop_animator_ticked_get(void)
1016{ 1337{
1338 DBG("ecore_main_loop_animator_ticked_get");
1017 return _ecore_animator_run_get(); 1339 return _ecore_animator_run_get();
1018} 1340}
1019 1341
@@ -1039,6 +1361,7 @@ _ecore_main_fd_handler_add(int fd,
1039 Ecore_Fd_Cb buf_func, 1361 Ecore_Fd_Cb buf_func,
1040 const void *buf_data) 1362 const void *buf_data)
1041{ 1363{
1364 DBG("_ecore_main_fd_handler_add");
1042 Ecore_Fd_Handler *fdh = NULL; 1365 Ecore_Fd_Handler *fdh = NULL;
1043 1366
1044 if ((fd < 0) || (flags == 0) || (!func)) return NULL; 1367 if ((fd < 0) || (flags == 0) || (!func)) return NULL;
@@ -1388,7 +1711,7 @@ _ecore_main_prepare_handlers(void)
1388 } 1711 }
1389} 1712}
1390 1713
1391#ifndef USE_G_MAIN_LOOP 1714#if !defined(USE_G_MAIN_LOOP)
1392static int 1715static int
1393_ecore_main_select(double timeout) 1716_ecore_main_select(double timeout)
1394{ 1717{
@@ -1750,8 +2073,121 @@ _ecore_main_fd_handlers_buf_call(void)
1750 return ret; 2073 return ret;
1751} 2074}
1752 2075
1753#ifndef USE_G_MAIN_LOOP 2076#ifdef HAVE_LIBUV
2077static void
2078_ecore_main_loop_uv_prepare(uv_prepare_t* handle EINA_UNUSED)
2079{
2080 _ecore_lock();
2081 _dl_uv_timer_stop(&_ecore_main_uv_handle_timers);
2082 if(in_main_loop == 0 && do_quit)
2083 {
2084 _ecore_main_fd_handlers_cleanup();
2085
2086 while (fd_handlers)
2087 {
2088 Ecore_Fd_Handler *fdh;
2089
2090 fdh = fd_handlers;
2091 fd_handlers = (Ecore_Fd_Handler *)eina_inlist_remove(EINA_INLIST_GET(fd_handlers),
2092 EINA_INLIST_GET(fdh));
2093 _ecore_main_fdh_poll_del(fdh);
2094 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
2095 ecore_fd_handler_mp_free(fdh);
2096 }
2097 if (fd_handlers_with_buffer)
2098 fd_handlers_with_buffer = eina_list_free(fd_handlers_with_buffer);
2099 if (fd_handlers_with_prep)
2100 fd_handlers_with_prep = eina_list_free(fd_handlers_with_prep);
2101 if (fd_handlers_to_delete)
2102 fd_handlers_to_delete = eina_list_free(fd_handlers_to_delete);
2103 if (file_fd_handlers)
2104 file_fd_handlers = eina_list_free(file_fd_handlers);
2105
2106 fd_handlers_to_call = NULL;
2107 fd_handlers_to_call_current = NULL;
2108 fd_handlers_to_delete = NULL;
2109 fd_handler_current = NULL;
2110
2111 _dl_uv_prepare_stop(&_ecore_main_uv_prepare);
2112 _dl_uv_check_stop(&_ecore_main_uv_check);
2113 _dl_uv_stop(_dl_uv_default_loop());
2114
2115 fprintf(stderr, "%s:%d Should close loop event, is alive? %d\n", __func__, __LINE__, (int)_dl_uv_loop_alive(_dl_uv_default_loop()));
2116
2117 _ecore_unlock();
2118 return;
2119 }
2120
2121 in_main_loop++;
2122
2123 if(!_ecore_main_uv_idling)
2124 {
2125 _ecore_main_uv_idling = EINA_TRUE;
2126 _ecore_idle_enterer_call();
2127 _ecore_throttle();
2128 }
2129
2130 double t = -1;
2131 if(_ecore_main_uv_idling)
2132 {
2133 _ecore_idler_all_call();
2134 DBG("called idles");
2135 if(_ecore_idler_exist() || _ecore_event_exist())
2136 t = 0.0;
2137 }
2138
2139 if (do_quit)
2140 {
2141 DBG("do quit outside loop");
2142
2143 if(_ecore_main_uv_idling)
2144 {
2145 _ecore_idle_exiter_call();
2146 _ecore_animator_run_reset();
2147
2148 _ecore_main_uv_idling = EINA_FALSE;
2149 }
2150
2151 t = -1;
2152
2153 _ecore_time_loop_time = ecore_time_get();
2154 _ecore_timer_enable_new();
2155
2156 goto done;
2157 }
2158
2159 assert(!fd_handlers_to_call);
2160
2161 _ecore_time_loop_time = ecore_time_get();
2162 _ecore_timer_enable_new();
2163 if (_ecore_timers_exists() || t >= 0)
2164 {
2165 double t1 = _ecore_timer_next_get();
2166 if(t < 0 || (t1 >= 0 && t1 < t)) t = t1;
2167 DBG("Should awake after %f", t);
2168
2169 if (t >= 0.0)
2170 {
2171 //_dl_uv_timer_stop(&_ecore_main_uv_handle_timers);
2172 _dl_uv_timer_start(&_ecore_main_uv_handle_timers, &_ecore_main_loop_timer_run, t * 1000
2173 , 0);
2174 }
2175 else
2176 DBG("Is not going to awake with timer");
2177 }
2178 else
2179 DBG("Is not going to awake with timer");
2180
2181 done:
2182 if (fd_handlers_with_prep)
2183 _ecore_main_prepare_handlers();
2184
2185 _ecore_unlock();
2186 in_main_loop--;
2187}
2188#endif
1754 2189
2190#if !defined(USE_G_MAIN_LOOP)
1755enum { 2191enum {
1756 SPIN_MORE, 2192 SPIN_MORE,
1757 SPIN_RESTART, 2193 SPIN_RESTART,