summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-22 12:20:06 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-22 12:22:17 +0900
commit29feb60d5086173cb7d9919aa4ff69d4ee9c8431 (patch)
tree5beb807a497bf7e82d637eb1e28992d27077b5e9 /src/lib/ecore
parent05e8d76021642eb3a24cb98edc3f4c291e88188d (diff)
ecore - fix epoll ifdefs and case handling
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/ecore_main.c87
1 files changed, 59 insertions, 28 deletions
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index 10011d9aff..22e2f45138 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -311,9 +311,11 @@ static double t1 = 0.0;
311static double t2 = 0.0; 311static double t2 = 0.0;
312#endif 312#endif
313 313
314static int timer_fd = -1; 314#ifdef HAVE_EPOLL
315static int epoll_fd = -1; 315static int epoll_fd = -1;
316static pid_t epoll_pid; 316static pid_t epoll_pid;
317#endif
318static int timer_fd = -1;
317 319
318#ifdef USE_G_MAIN_LOOP 320#ifdef USE_G_MAIN_LOOP
319static GPollFD ecore_epoll_fd; 321static GPollFD ecore_epoll_fd;
@@ -330,7 +332,8 @@ static gboolean ecore_fds_ready;
330static inline void 332static inline void
331_ecore_fd_valid(void) 333_ecore_fd_valid(void)
332{ 334{
333 if (HAVE_EPOLL && epoll_fd >= 0) 335#ifdef HAVE_EPOLL
336 if (epoll_fd >= 0)
334 { 337 {
335 if (fcntl(epoll_fd, F_GETFD) < 0) 338 if (fcntl(epoll_fd, F_GETFD) < 0)
336 { 339 {
@@ -342,6 +345,7 @@ _ecore_fd_valid(void)
342#endif 345#endif
343 } 346 }
344 } 347 }
348#endif
345} 349}
346#endif 350#endif
347 351
@@ -367,15 +371,16 @@ _ecore_try_add_to_call_list(Ecore_Fd_Handler *fdh)
367 } 371 }
368} 372}
369 373
374#ifdef HAVE_EPOLL
370static inline int 375static inline int
371_ecore_get_epoll_fd(void) 376_ecore_get_epoll_fd(void)
372{ 377{
373 if (epoll_pid && epoll_pid != getpid()) 378 if (epoll_pid && (epoll_pid != getpid()))
374 { 379 {
375 /* forked! */ 380 /* forked! */
376 _ecore_main_loop_shutdown(); 381 _ecore_main_loop_shutdown();
377 } 382 }
378 if (epoll_pid == 0 && epoll_fd < 0) 383 if ((epoll_pid == 0) && (epoll_fd < 0))
379 { 384 {
380 _ecore_main_loop_init(); 385 _ecore_main_loop_init();
381 } 386 }
@@ -388,7 +393,6 @@ _ecore_epoll_add(int efd,
388 int events, 393 int events,
389 void *ptr) 394 void *ptr)
390{ 395{
391
392 struct epoll_event ev; 396 struct epoll_event ev;
393 397
394 memset(&ev, 0, sizeof (ev)); 398 memset(&ev, 0, sizeof (ev));
@@ -407,6 +411,7 @@ _ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
407 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR | EPOLLPRI; 411 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR | EPOLLPRI;
408 return events; 412 return events;
409} 413}
414#endif
410 415
411#ifdef USE_G_MAIN_LOOP 416#ifdef USE_G_MAIN_LOOP
412static inline int 417static inline int
@@ -470,11 +475,12 @@ _ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
470 DBG("_ecore_main_fdh_poll_add"); 475 DBG("_ecore_main_fdh_poll_add");
471 int r = 0; 476 int r = 0;
472 477
478#ifdef HAVE_EPOLL
473#ifdef HAVE_LIBUV 479#ifdef HAVE_LIBUV
474 if(!_dl_uv_run) 480 if(!_dl_uv_run)
475#endif 481#endif
476 { 482 {
477 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 483 if ((!fdh->file) && (epoll_fd >= 0))
478 { 484 {
479 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd, 485 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd,
480 _ecore_poll_events_from_fdh(fdh), fdh); 486 _ecore_poll_events_from_fdh(fdh), fdh);
@@ -483,6 +489,7 @@ _ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
483#ifdef HAVE_LIBUV 489#ifdef HAVE_LIBUV
484 else 490 else
485#endif 491#endif
492#endif
486 { 493 {
487#ifdef HAVE_LIBUV 494#ifdef HAVE_LIBUV
488 if(!fdh->file) 495 if(!fdh->file)
@@ -521,11 +528,12 @@ _ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
521static inline void 528static inline void
522_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh) 529_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh)
523{ 530{
531#ifdef HAVE_EPOLL
524#ifdef HAVE_LIBUV 532#ifdef HAVE_LIBUV
525 if(!_dl_uv_run) 533 if(!_dl_uv_run)
526#endif 534#endif
527 { 535 {
528 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 536 if ((!fdh->file) && (epoll_fd >= 0))
529 { 537 {
530 struct epoll_event ev; 538 struct epoll_event ev;
531 int efd = _ecore_get_epoll_fd(); 539 int efd = _ecore_get_epoll_fd();
@@ -552,6 +560,7 @@ _ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh)
552#ifdef HAVE_LIBUV 560#ifdef HAVE_LIBUV
553 else 561 else
554#endif 562#endif
563#endif
555 { 564 {
556#ifdef HAVE_LIBUV 565#ifdef HAVE_LIBUV
557 DBG("_ecore_main_fdh_poll_del libuv %p", fdh); 566 DBG("_ecore_main_fdh_poll_del libuv %p", fdh);
@@ -573,11 +582,12 @@ _ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
573{ 582{
574 DBG("_ecore_main_fdh_poll_modify %p", fdh); 583 DBG("_ecore_main_fdh_poll_modify %p", fdh);
575 int r = 0; 584 int r = 0;
585#ifdef HAVE_EPOLL
576#ifdef HAVE_LIBUV 586#ifdef HAVE_LIBUV
577 if(!_dl_uv_run) 587 if(!_dl_uv_run)
578#endif 588#endif
579 { 589 {
580 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0) 590 if ((!fdh->file) && (epoll_fd >= 0))
581 { 591 {
582 struct epoll_event ev; 592 struct epoll_event ev;
583 int efd = _ecore_get_epoll_fd(); 593 int efd = _ecore_get_epoll_fd();
@@ -592,6 +602,7 @@ _ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
592#ifdef HAVE_LIBUV 602#ifdef HAVE_LIBUV
593 else 603 else
594#endif 604#endif
605#endif
595 { 606 {
596#ifdef HAVE_LIBUV 607#ifdef HAVE_LIBUV
597 _dl_uv_poll_start(&fdh->uv_handle, _ecore_main_uv_events_from_fdh(fdh) 608 _dl_uv_poll_start(&fdh->uv_handle, _ecore_main_uv_events_from_fdh(fdh)
@@ -606,6 +617,7 @@ _ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
606 return r; 617 return r;
607} 618}
608 619
620#ifdef HAVE_EPOLL
609static inline int 621static inline int
610_ecore_main_fdh_epoll_mark_active(void) 622_ecore_main_fdh_epoll_mark_active(void)
611{ 623{
@@ -652,6 +664,7 @@ _ecore_main_fdh_epoll_mark_active(void)
652 664
653 return ret; 665 return ret;
654} 666}
667#endif
655 668
656#ifdef USE_G_MAIN_LOOP 669#ifdef USE_G_MAIN_LOOP
657 670
@@ -716,7 +729,8 @@ _ecore_main_gsource_prepare(GSource *source EINA_UNUSED,
716 { 729 {
717 int r = -1; 730 int r = -1;
718 double t = _efl_loop_timer_next_get(); 731 double t = _efl_loop_timer_next_get();
719 if (timer_fd >= 0 && t > 0.0) 732
733 if ((timer_fd >= 0) && (t > 0.0))
720 { 734 {
721 struct itimerspec ts; 735 struct itimerspec ts;
722 736
@@ -785,13 +799,13 @@ _ecore_main_gsource_check(GSource *source EINA_UNUSED)
785 { 799 {
786 uint64_t count = 0; 800 uint64_t count = 0;
787 int r = read(timer_fd, &count, sizeof count); 801 int r = read(timer_fd, &count, sizeof count);
788 if (r == -1 && errno == EAGAIN) 802 if ((r == -1) && (errno == EAGAIN))
789 ; 803 ;
790 else if (r == sizeof count) 804 else if (r == sizeof count)
791 ret = TRUE; 805 ret = TRUE;
792 else 806 else
793 { 807 {
794 /* unexpected things happened... fail back to old way */ 808 /* unexpected things happened... fail back to old way */
795 ERR("timer read returned %d (errno=%d)", r, errno); 809 ERR("timer read returned %d (errno=%d)", r, errno);
796 close(timer_fd); 810 close(timer_fd);
797 timer_fd = -1; 811 timer_fd = -1;
@@ -802,9 +816,11 @@ _ecore_main_gsource_check(GSource *source EINA_UNUSED)
802 ret = TRUE; 816 ret = TRUE;
803 817
804 /* check if fds are ready */ 818 /* check if fds are ready */
805 if (HAVE_EPOLL && epoll_fd >= 0) 819#ifdef HAVE_EPOLL
820 if (epoll_fd >= 0)
806 ecore_fds_ready = (_ecore_main_fdh_epoll_mark_active() > 0); 821 ecore_fds_ready = (_ecore_main_fdh_epoll_mark_active() > 0);
807 else 822 else
823#endif
808 ecore_fds_ready = (_ecore_main_fdh_glib_mark_active() > 0); 824 ecore_fds_ready = (_ecore_main_fdh_glib_mark_active() > 0);
809 _ecore_main_fd_handlers_cleanup(); 825 _ecore_main_fd_handlers_cleanup();
810 if (ecore_fds_ready) 826 if (ecore_fds_ready)
@@ -1023,22 +1039,28 @@ _ecore_main_loop_init(void)
1023 // Please note that this function is being also called in case of a bad fd to reset the main loop. 1039 // Please note that this function is being also called in case of a bad fd to reset the main loop.
1024 1040
1025 DBG("_ecore_main_loop_init"); 1041 DBG("_ecore_main_loop_init");
1042#ifdef HAVE_EPOLL
1026 epoll_fd = epoll_create(1); 1043 epoll_fd = epoll_create(1);
1027 if ((epoll_fd < 0) && HAVE_EPOLL) 1044 if (epoll_fd < 0)
1028 WRN("Failed to create epoll fd!"); 1045 WRN("Failed to create epoll fd!");
1029 epoll_pid = getpid(); 1046 else
1030 eina_file_close_on_exec(epoll_fd, EINA_TRUE);
1031
1032 /* add polls on all our file descriptors */
1033 Ecore_Fd_Handler *fdh;
1034 EINA_INLIST_FOREACH(fd_handlers, fdh)
1035 { 1047 {
1036 if (fdh->delete_me) 1048 eina_file_close_on_exec(epoll_fd, EINA_TRUE);
1037 continue; 1049
1038 _ecore_epoll_add(epoll_fd, fdh->fd, 1050 epoll_pid = getpid();
1039 _ecore_poll_events_from_fdh(fdh), fdh); 1051
1040 _ecore_main_fdh_poll_add(fdh); 1052 /* add polls on all our file descriptors */
1053 Ecore_Fd_Handler *fdh;
1054 EINA_INLIST_FOREACH(fd_handlers, fdh)
1055 {
1056 if (fdh->delete_me) continue;
1057 _ecore_epoll_add(epoll_fd, fdh->fd,
1058 _ecore_poll_events_from_fdh(fdh), fdh);
1059 _ecore_main_fdh_poll_add(fdh);
1060 }
1041 } 1061 }
1062#endif
1063
1042#ifdef HAVE_LIBUV 1064#ifdef HAVE_LIBUV
1043 { 1065 {
1044 DBG("loading lib uv"); 1066 DBG("loading lib uv");
@@ -1118,7 +1140,8 @@ _ecore_main_loop_init(void)
1118 else 1140 else
1119 { 1141 {
1120 g_source_set_priority(ecore_glib_source, G_PRIORITY_HIGH_IDLE + 20); 1142 g_source_set_priority(ecore_glib_source, G_PRIORITY_HIGH_IDLE + 20);
1121 if (HAVE_EPOLL && epoll_fd >= 0) 1143#ifdef HAVE_EPOLL
1144 if (epoll_fd >= 0)
1122 { 1145 {
1123 /* epoll multiplexes fds into the g_main_loop */ 1146 /* epoll multiplexes fds into the g_main_loop */
1124 ecore_epoll_fd.fd = epoll_fd; 1147 ecore_epoll_fd.fd = epoll_fd;
@@ -1126,7 +1149,7 @@ _ecore_main_loop_init(void)
1126 ecore_epoll_fd.revents = 0; 1149 ecore_epoll_fd.revents = 0;
1127 g_source_add_poll(ecore_glib_source, &ecore_epoll_fd); 1150 g_source_add_poll(ecore_glib_source, &ecore_epoll_fd);
1128 } 1151 }
1129 1152#endif
1130 /* timerfd gives us better than millisecond accuracy in g_main_loop */ 1153 /* timerfd gives us better than millisecond accuracy in g_main_loop */
1131 timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); 1154 timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
1132 if (timer_fd < 0) 1155 if (timer_fd < 0)
@@ -1164,12 +1187,14 @@ _ecore_main_loop_shutdown(void)
1164 1187
1165 detect_time_changes_stop(); 1188 detect_time_changes_stop();
1166 1189
1190#ifdef HAVE_EPOLL
1167 if (epoll_fd >= 0) 1191 if (epoll_fd >= 0)
1168 { 1192 {
1169 close(epoll_fd); 1193 close(epoll_fd);
1170 epoll_fd = -1; 1194 epoll_fd = -1;
1171 } 1195 }
1172 epoll_pid = 0; 1196 epoll_pid = 0;
1197#endif
1173 1198
1174 if (timer_fd >= 0) 1199 if (timer_fd >= 0)
1175 { 1200 {
@@ -1711,8 +1736,10 @@ _ecore_main_select(double timeout)
1711 if (fd_handlers_with_prep) 1736 if (fd_handlers_with_prep)
1712 _ecore_main_prepare_handlers(); 1737 _ecore_main_prepare_handlers();
1713 1738
1714 if (!HAVE_EPOLL || epoll_fd < 0) 1739#ifdef HAVE_EPOLL
1740 if (epoll_fd < 0)
1715 { 1741 {
1742#endif
1716 EINA_INLIST_FOREACH(fd_handlers, fdh) 1743 EINA_INLIST_FOREACH(fd_handlers, fdh)
1717 { 1744 {
1718 if (!fdh->delete_me) 1745 if (!fdh->delete_me)
@@ -1735,12 +1762,14 @@ _ecore_main_select(double timeout)
1735 } 1762 }
1736 } 1763 }
1737 } 1764 }
1765#ifdef HAVE_EPOLL
1738 else 1766 else
1739 { 1767 {
1740 /* polling on the epoll fd will wake when an fd in the epoll set is active */ 1768 /* polling on the epoll fd will wake when an fd in the epoll set is active */
1741 max_fd = _ecore_get_epoll_fd(); 1769 max_fd = _ecore_get_epoll_fd();
1742 FD_SET(max_fd, &rfds); 1770 FD_SET(max_fd, &rfds);
1743 } 1771 }
1772#endif
1744 EINA_LIST_FOREACH(file_fd_handlers, l, fdh) 1773 EINA_LIST_FOREACH(file_fd_handlers, l, fdh)
1745 if (!fdh->delete_me) 1774 if (!fdh->delete_me)
1746 { 1775 {
@@ -1781,9 +1810,11 @@ _ecore_main_select(double timeout)
1781 } 1810 }
1782 if (ret > 0) 1811 if (ret > 0)
1783 { 1812 {
1784 if (HAVE_EPOLL && epoll_fd >= 0) 1813#ifdef HAVE_EPOLL
1814 if (epoll_fd >= 0)
1785 _ecore_main_fdh_epoll_mark_active(); 1815 _ecore_main_fdh_epoll_mark_active();
1786 else 1816 else
1817#endif
1787 { 1818 {
1788 EINA_INLIST_FOREACH(fd_handlers, fdh) 1819 EINA_INLIST_FOREACH(fd_handlers, fdh)
1789 { 1820 {