summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2011-10-21 05:40:39 +0000
committerCarsten Haitzler <raster@rasterman.com>2011-10-21 05:40:39 +0000
commit58cbf16625119b70e515d212861e499082c1221d (patch)
tree3b1b802fb7bfb4c53ac446acb5dc799097f07f95 /legacy/ecore/src/lib/ecore/ecore_main.c
parent8893a9ff35f58e012be3cc838bd94268add13e10 (diff)
ran ecrustify on ecore. some manual fixing too.
SVN revision: 64238
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_main.c677
1 files changed, 359 insertions, 318 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_main.c b/legacy/ecore/src/lib/ecore/ecore_main.c
index df657cba76..2e50e15c93 100644
--- a/legacy/ecore/src/lib/ecore/ecore_main.c
+++ b/legacy/ecore/src/lib/ecore/ecore_main.c
@@ -31,7 +31,7 @@
31#endif 31#endif
32 32
33#ifdef HAVE_ISFINITE 33#ifdef HAVE_ISFINITE
34# define ECORE_FINITE(t) isfinite(t) 34# define ECORE_FINITE(t) isfinite(t)
35#else 35#else
36# ifdef _MSC_VER 36# ifdef _MSC_VER
37# define ECORE_FINITE(t) _finite(t) 37# define ECORE_FINITE(t) _finite(t)
@@ -59,14 +59,14 @@
59#include "ecore_private.h" 59#include "ecore_private.h"
60 60
61#ifdef HAVE_SYS_EPOLL_H 61#ifdef HAVE_SYS_EPOLL_H
62# define HAVE_EPOLL 1 62# define HAVE_EPOLL 1
63# include <sys/epoll.h> 63# include <sys/epoll.h>
64#else 64#else
65 65
66# define HAVE_EPOLL 0 66# define HAVE_EPOLL 0
67# define EPOLLIN 1 67# define EPOLLIN 1
68# define EPOLLOUT 2 68# define EPOLLOUT 2
69# define EPOLLERR 8 69# define EPOLLERR 8
70 70
71#define EPOLL_CTL_ADD 1 71#define EPOLL_CTL_ADD 1
72#define EPOLL_CTL_DEL 2 72#define EPOLL_CTL_DEL 2
@@ -79,7 +79,8 @@ typedef union epoll_data {
79 uint64_t u64; 79 uint64_t u64;
80} epoll_data_t; 80} epoll_data_t;
81 81
82struct epoll_event { 82struct epoll_event
83{
83 uint32_t events; 84 uint32_t events;
84 epoll_data_t data; 85 epoll_data_t data;
85}; 86};
@@ -87,21 +88,25 @@ struct epoll_event {
87static inline int 88static inline int
88epoll_create(int size __UNUSED__) 89epoll_create(int size __UNUSED__)
89{ 90{
90 return -1; 91 return -1;
91} 92}
92 93
93static inline int 94static inline int
94epoll_wait(int epfd __UNUSED__, struct epoll_event *events __UNUSED__, 95epoll_wait(int epfd __UNUSED__,
95 int maxevents __UNUSED__, int timeout __UNUSED__) 96 struct epoll_event *events __UNUSED__,
97 int maxevents __UNUSED__,
98 int timeout __UNUSED__)
96{ 99{
97 return -1; 100 return -1;
98} 101}
99 102
100static inline int 103static inline int
101epoll_ctl(int epfd __UNUSED__, int op __UNUSED__, int fd __UNUSED__, 104epoll_ctl(int epfd __UNUSED__,
105 int op __UNUSED__,
106 int fd __UNUSED__,
102 struct epoll_event *event __UNUSED__) 107 struct epoll_event *event __UNUSED__)
103{ 108{
104 return -1; 109 return -1;
105} 110}
106 111
107#endif 112#endif
@@ -114,20 +119,24 @@ epoll_ctl(int epfd __UNUSED__, int op __UNUSED__, int fd __UNUSED__,
114#define CLOCK_MONOTONIC 0 /* bogus value */ 119#define CLOCK_MONOTONIC 0 /* bogus value */
115#endif 120#endif
116#ifndef TFD_NONBLOCK 121#ifndef TFD_NONBLOCK
117#define TFD_NONBLOCK 0 /* bogus value */ 122#define TFD_NONBLOCK 0 /* bogus value */
118#endif 123#endif
119static inline int 124static inline int
120timerfd_create(int clockid __UNUSED__, int flags __UNUSED__) 125timerfd_create(int clockid __UNUSED__,
126 int flags __UNUSED__)
121{ 127{
122 return -1; 128 return -1;
123} 129}
130
124static inline int 131static inline int
125timerfd_settime(int fd __UNUSED__, int flags __UNUSED__, 132timerfd_settime(int fd __UNUSED__,
133 int flags __UNUSED__,
126 const struct itimerspec *new_value __UNUSED__, 134 const struct itimerspec *new_value __UNUSED__,
127 struct itimerspec *old_value __UNUSED__) 135 struct itimerspec *old_value __UNUSED__)
128{ 136{
129 return -1; 137 return -1;
130} 138}
139
131#endif /* HAVE_SYS_TIMERFD_H */ 140#endif /* HAVE_SYS_TIMERFD_H */
132 141
133#ifdef USE_G_MAIN_LOOP 142#ifdef USE_G_MAIN_LOOP
@@ -139,23 +148,23 @@ timerfd_settime(int fd __UNUSED__, int flags __UNUSED__,
139struct _Ecore_Fd_Handler 148struct _Ecore_Fd_Handler
140{ 149{
141 EINA_INLIST; 150 EINA_INLIST;
142 ECORE_MAGIC; 151 ECORE_MAGIC;
143 Ecore_Fd_Handler *next_ready; 152 Ecore_Fd_Handler *next_ready;
144 int fd; 153 int fd;
145 Ecore_Fd_Handler_Flags flags; 154 Ecore_Fd_Handler_Flags flags;
146 Ecore_Fd_Cb func; 155 Ecore_Fd_Cb func;
147 void *data; 156 void *data;
148 Ecore_Fd_Cb buf_func; 157 Ecore_Fd_Cb buf_func;
149 void *buf_data; 158 void *buf_data;
150 Ecore_Fd_Prep_Cb prep_func; 159 Ecore_Fd_Prep_Cb prep_func;
151 void *prep_data; 160 void *prep_data;
152 int references; 161 int references;
153 Eina_Bool read_active : 1; 162 Eina_Bool read_active : 1;
154 Eina_Bool write_active : 1; 163 Eina_Bool write_active : 1;
155 Eina_Bool error_active : 1; 164 Eina_Bool error_active : 1;
156 Eina_Bool delete_me : 1; 165 Eina_Bool delete_me : 1;
157#if defined(USE_G_MAIN_LOOP) 166#if defined(USE_G_MAIN_LOOP)
158 GPollFD gfd; 167 GPollFD gfd;
159#endif 168#endif
160}; 169};
161 170
@@ -163,7 +172,7 @@ struct _Ecore_Fd_Handler
163struct _Ecore_Win32_Handler 172struct _Ecore_Win32_Handler
164{ 173{
165 EINA_INLIST; 174 EINA_INLIST;
166 ECORE_MAGIC; 175 ECORE_MAGIC;
167 HANDLE h; 176 HANDLE h;
168 Ecore_Win32_Handle_Cb func; 177 Ecore_Win32_Handle_Cb func;
169 void *data; 178 void *data;
@@ -172,7 +181,6 @@ struct _Ecore_Win32_Handler
172}; 181};
173#endif 182#endif
174 183
175
176#ifndef USE_G_MAIN_LOOP 184#ifndef USE_G_MAIN_LOOP
177static int _ecore_main_select(double timeout); 185static int _ecore_main_select(double timeout);
178#endif 186#endif
@@ -190,29 +198,32 @@ static void _ecore_main_loop_iterate_internal(int once_only);
190#endif 198#endif
191 199
192#ifdef _WIN32 200#ifdef _WIN32
193static int _ecore_main_win32_select(int nfds, fd_set *readfds, fd_set *writefds, 201static int _ecore_main_win32_select(int nfds,
194 fd_set *exceptfds, struct timeval *timeout); 202 fd_set *readfds,
203 fd_set *writefds,
204 fd_set *exceptfds,
205 struct timeval *timeout);
195static void _ecore_main_win32_handlers_cleanup(void); 206static void _ecore_main_win32_handlers_cleanup(void);
196#endif 207#endif
197 208
198static int in_main_loop = 0; 209static int in_main_loop = 0;
199#ifndef USE_G_MAIN_LOOP 210#ifndef USE_G_MAIN_LOOP
200static int do_quit = 0; 211static int do_quit = 0;
201#endif 212#endif
202static Ecore_Fd_Handler *fd_handlers = NULL; 213static Ecore_Fd_Handler *fd_handlers = NULL;
203static Ecore_Fd_Handler *fd_handler_current = NULL; 214static Ecore_Fd_Handler *fd_handler_current = NULL;
204static Eina_List *fd_handlers_with_prep = NULL; 215static Eina_List *fd_handlers_with_prep = NULL;
205static Eina_List *fd_handlers_with_buffer = NULL; 216static Eina_List *fd_handlers_with_buffer = NULL;
206static Eina_List *fd_handlers_to_delete = NULL; 217static Eina_List *fd_handlers_to_delete = NULL;
207 218
208/* single linked list of ready fdhs, terminated by loop to self */ 219/* single linked list of ready fdhs, terminated by loop to self */
209static Ecore_Fd_Handler *fd_handlers_to_call; 220static Ecore_Fd_Handler *fd_handlers_to_call;
210static Ecore_Fd_Handler *fd_handlers_to_call_current; 221static Ecore_Fd_Handler *fd_handlers_to_call_current;
211 222
212#ifdef _WIN32 223#ifdef _WIN32
213static Ecore_Win32_Handler *win32_handlers = NULL; 224static Ecore_Win32_Handler *win32_handlers = NULL;
214static Ecore_Win32_Handler *win32_handler_current = NULL; 225static Ecore_Win32_Handler *win32_handler_current = NULL;
215static Eina_Bool win32_handlers_delete_me = EINA_FALSE; 226static Eina_Bool win32_handlers_delete_me = EINA_FALSE;
216#endif 227#endif
217 228
218#ifdef _WIN32 229#ifdef _WIN32
@@ -225,8 +236,8 @@ Ecore_Select_Function main_loop_select = select;
225#endif 236#endif
226 237
227#ifndef USE_G_MAIN_LOOP 238#ifndef USE_G_MAIN_LOOP
228static double t1 = 0.0; 239static double t1 = 0.0;
229static double t2 = 0.0; 240static double t2 = 0.0;
230#endif 241#endif
231 242
232static int timer_fd = -1; 243static int timer_fd = -1;
@@ -238,7 +249,7 @@ static GPollFD ecore_epoll_fd;
238static GPollFD ecore_timer_fd; 249static GPollFD ecore_timer_fd;
239static GSource *ecore_glib_source; 250static GSource *ecore_glib_source;
240static guint ecore_glib_source_id; 251static guint ecore_glib_source_id;
241static GMainLoop* ecore_main_loop; 252static GMainLoop *ecore_main_loop;
242static gboolean ecore_idling; 253static gboolean ecore_idling;
243static gboolean _ecore_glib_idle_enterer_called; 254static gboolean _ecore_glib_idle_enterer_called;
244static gboolean ecore_fds_ready; 255static gboolean ecore_fds_ready;
@@ -261,18 +272,18 @@ static inline void
261_ecore_try_add_to_call_list(Ecore_Fd_Handler *fdh) 272_ecore_try_add_to_call_list(Ecore_Fd_Handler *fdh)
262{ 273{
263 /* check if this fdh is already in the list */ 274 /* check if this fdh is already in the list */
264 if (fdh->next_ready) 275 if (fdh->next_ready)
265 return; 276 return;
266 if (fdh->read_active || fdh->write_active || fdh->error_active) 277 if (fdh->read_active || fdh->write_active || fdh->error_active)
267 { 278 {
268 /* 279 /*
269 * make sure next_ready is non-null by pointing to ourselves 280 * make sure next_ready is non-null by pointing to ourselves
270 * use that to indicate this fdh is in the ready list 281 * use that to indicate this fdh is in the ready list
271 * insert at the head of the list to avoid trouble 282 * insert at the head of the list to avoid trouble
272 */ 283 */
273 fdh->next_ready = fd_handlers_to_call ? fd_handlers_to_call : fdh; 284 fdh->next_ready = fd_handlers_to_call ? fd_handlers_to_call : fdh;
274 fd_handlers_to_call = fdh; 285 fd_handlers_to_call = fdh;
275 } 286 }
276} 287}
277 288
278static inline int 289static inline int
@@ -281,7 +292,7 @@ _ecore_get_epoll_fd(void)
281 if (epoll_pid && epoll_pid != getpid()) 292 if (epoll_pid && epoll_pid != getpid())
282 { 293 {
283 /* forked! */ 294 /* forked! */
284 _ecore_main_loop_shutdown(); 295 _ecore_main_loop_shutdown();
285 } 296 }
286 if (epoll_pid == 0 && epoll_fd < 0) 297 if (epoll_pid == 0 && epoll_fd < 0)
287 { 298 {
@@ -291,7 +302,10 @@ _ecore_get_epoll_fd(void)
291} 302}
292 303
293static inline int 304static inline int
294_ecore_epoll_add(int efd, int fd, int events, void *ptr) 305_ecore_epoll_add(int efd,
306 int fd,
307 int events,
308 void *ptr)
295{ 309{
296 struct epoll_event ev; 310 struct epoll_event ev;
297 311
@@ -306,7 +320,7 @@ static inline int
306_ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh) 320_ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
307{ 321{
308 int events = 0; 322 int events = 0;
309 if (fdh->flags & ECORE_FD_READ) events |= EPOLLIN; 323 if (fdh->flags & ECORE_FD_READ) events |= EPOLLIN;
310 if (fdh->flags & ECORE_FD_WRITE) events |= EPOLLOUT; 324 if (fdh->flags & ECORE_FD_WRITE) events |= EPOLLOUT;
311 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR; 325 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR;
312 return events; 326 return events;
@@ -317,11 +331,12 @@ static inline int
317_gfd_events_from_fdh(Ecore_Fd_Handler *fdh) 331_gfd_events_from_fdh(Ecore_Fd_Handler *fdh)
318{ 332{
319 int events = 0; 333 int events = 0;
320 if (fdh->flags & ECORE_FD_READ) events |= G_IO_IN; 334 if (fdh->flags & ECORE_FD_READ) events |= G_IO_IN;
321 if (fdh->flags & ECORE_FD_WRITE) events |= G_IO_OUT; 335 if (fdh->flags & ECORE_FD_WRITE) events |= G_IO_OUT;
322 if (fdh->flags & ECORE_FD_ERROR) events |= G_IO_ERR; 336 if (fdh->flags & ECORE_FD_ERROR) events |= G_IO_ERR;
323 return events; 337 return events;
324} 338}
339
325#endif 340#endif
326 341
327static inline int 342static inline int
@@ -412,7 +427,8 @@ _ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
412 return r; 427 return r;
413} 428}
414 429
415static inline int _ecore_main_fdh_epoll_mark_active(void) 430static inline int
431_ecore_main_fdh_epoll_mark_active(void)
416{ 432{
417 struct epoll_event ev[32]; 433 struct epoll_event ev[32];
418 int i, ret; 434 int i, ret;
@@ -459,7 +475,8 @@ static inline int _ecore_main_fdh_epoll_mark_active(void)
459 475
460#ifdef USE_G_MAIN_LOOP 476#ifdef USE_G_MAIN_LOOP
461 477
462static inline int _ecore_main_fdh_glib_mark_active(void) 478static inline int
479_ecore_main_fdh_glib_mark_active(void)
463{ 480{
464 Ecore_Fd_Handler *fdh; 481 Ecore_Fd_Handler *fdh;
465 int ret = 0; 482 int ret = 0;
@@ -468,18 +485,18 @@ static inline int _ecore_main_fdh_glib_mark_active(void)
468 EINA_INLIST_FOREACH(fd_handlers, fdh) 485 EINA_INLIST_FOREACH(fd_handlers, fdh)
469 { 486 {
470 if (fdh->delete_me) 487 if (fdh->delete_me)
471 continue; 488 continue;
472 489
473 if (fdh->gfd.revents & G_IO_IN) 490 if (fdh->gfd.revents & G_IO_IN)
474 fdh->read_active = EINA_TRUE; 491 fdh->read_active = EINA_TRUE;
475 if (fdh->gfd.revents & G_IO_OUT) 492 if (fdh->gfd.revents & G_IO_OUT)
476 fdh->write_active = EINA_TRUE; 493 fdh->write_active = EINA_TRUE;
477 if (fdh->gfd.revents & G_IO_ERR) 494 if (fdh->gfd.revents & G_IO_ERR)
478 fdh->error_active = EINA_TRUE; 495 fdh->error_active = EINA_TRUE;
479 496
480 _ecore_try_add_to_call_list(fdh); 497 _ecore_try_add_to_call_list(fdh);
481 498
482 if (fdh->gfd.revents & (G_IO_IN|G_IO_OUT|G_IO_ERR)) ret++; 499 if (fdh->gfd.revents & (G_IO_IN | G_IO_OUT | G_IO_ERR)) ret++;
483 } 500 }
484 501
485 return ret; 502 return ret;
@@ -487,7 +504,8 @@ static inline int _ecore_main_fdh_glib_mark_active(void)
487 504
488/* like we are about to enter main_loop_select in _ecore_main_select */ 505/* like we are about to enter main_loop_select in _ecore_main_select */
489static gboolean 506static gboolean
490_ecore_main_gsource_prepare(GSource *source __UNUSED__, gint *next_time) 507_ecore_main_gsource_prepare(GSource *source __UNUSED__,
508 gint *next_time)
491{ 509{
492 gboolean ready = FALSE; 510 gboolean ready = FALSE;
493 511
@@ -514,56 +532,56 @@ _ecore_main_gsource_prepare(GSource *source __UNUSED__, gint *next_time)
514 if (g_main_loop_is_running(ecore_main_loop)) 532 if (g_main_loop_is_running(ecore_main_loop))
515 { 533 {
516 /* only set idling state in dispatch */ 534 /* only set idling state in dispatch */
517 if (ecore_idling && !_ecore_idler_exist() && !_ecore_event_exist()) 535 if (ecore_idling && !_ecore_idler_exist() && !_ecore_event_exist())
518 { 536 {
519 if (_ecore_timers_exists()) 537 if (_ecore_timers_exists())
520 { 538 {
521 int r = -1; 539 int r = -1;
522 double t = _ecore_timer_next_get(); 540 double t = _ecore_timer_next_get();
523 if (timer_fd >= 0 && t > 0.0) 541 if (timer_fd >= 0 && t > 0.0)
524 { 542 {
525 struct itimerspec ts; 543 struct itimerspec ts;
526 544
527 ts.it_interval.tv_sec = 0; 545 ts.it_interval.tv_sec = 0;
528 ts.it_interval.tv_nsec = 0; 546 ts.it_interval.tv_nsec = 0;
529 ts.it_value.tv_sec = t; 547 ts.it_value.tv_sec = t;
530 ts.it_value.tv_nsec = fmod(t*NS_PER_SEC, NS_PER_SEC); 548 ts.it_value.tv_nsec = fmod(t * NS_PER_SEC, NS_PER_SEC);
531 549
532 /* timerfd cannot sleep for 0 time */ 550 /* timerfd cannot sleep for 0 time */
533 if (ts.it_value.tv_sec || ts.it_value.tv_nsec) 551 if (ts.it_value.tv_sec || ts.it_value.tv_nsec)
534 { 552 {
535 r = timerfd_settime(timer_fd, 0, &ts, NULL); 553 r = timerfd_settime(timer_fd, 0, &ts, NULL);
536 if (r < 0) 554 if (r < 0)
537 { 555 {
538 ERR("timer set returned %d (errno=%d)", r, errno); 556 ERR("timer set returned %d (errno=%d)", r, errno);
539 close(timer_fd); 557 close(timer_fd);
540 timer_fd = -1; 558 timer_fd = -1;
541 } 559 }
542 else 560 else
543 INF("sleeping for %ld s %06ldus", 561 INF("sleeping for %ld s %06ldus",
544 ts.it_value.tv_sec, 562 ts.it_value.tv_sec,
545 ts.it_value.tv_nsec/1000); 563 ts.it_value.tv_nsec / 1000);
546 } 564 }
547 } 565 }
548 if (r == -1) 566 if (r == -1)
549 { 567 {
550 *next_time = ceil(t * 1000.0); 568 *next_time = ceil(t * 1000.0);
551 if (t == 0.0) 569 if (t == 0.0)
552 ready = TRUE; 570 ready = TRUE;
553 } 571 }
554 } 572 }
555 else 573 else
556 *next_time = -1; 574 *next_time = -1;
557 } 575 }
558 else 576 else
559 { 577 {
560 *next_time = 0; 578 *next_time = 0;
561 if (_ecore_event_exist()) 579 if (_ecore_event_exist())
562 ready = TRUE; 580 ready = TRUE;
563 } 581 }
564 582
565 if (fd_handlers_with_prep) 583 if (fd_handlers_with_prep)
566 _ecore_main_prepare_handlers(); 584 _ecore_main_prepare_handlers();
567 } 585 }
568 else 586 else
569 ready = TRUE; 587 ready = TRUE;
@@ -597,10 +615,10 @@ _ecore_main_gsource_check(GSource *source __UNUSED__)
597 ret = TRUE; 615 ret = TRUE;
598 else 616 else
599 { 617 {
600 /* unexpected things happened... fail back to old way */ 618 /* unexpected things happened... fail back to old way */
601 ERR("timer read returned %d (errno=%d)", r, errno); 619 ERR("timer read returned %d (errno=%d)", r, errno);
602 close(timer_fd); 620 close(timer_fd);
603 timer_fd = -1; 621 timer_fd = -1;
604 } 622 }
605 } 623 }
606 } 624 }
@@ -628,7 +646,9 @@ _ecore_main_gsource_check(GSource *source __UNUSED__)
628 646
629/* like we just came out of main_loop_select in _ecore_main_select */ 647/* like we just came out of main_loop_select in _ecore_main_select */
630static gboolean 648static gboolean
631_ecore_main_gsource_dispatch(GSource *source __UNUSED__, GSourceFunc callback __UNUSED__, gpointer user_data __UNUSED__) 649_ecore_main_gsource_dispatch(GSource *source __UNUSED__,
650 GSourceFunc callback __UNUSED__,
651 gpointer user_data __UNUSED__)
632{ 652{
633 gboolean events_ready, timers_ready, idlers_ready; 653 gboolean events_ready, timers_ready, idlers_ready;
634 double next_time; 654 double next_time;
@@ -704,8 +724,8 @@ _ecore_main_gsource_finalize(GSource *source __UNUSED__)
704 724
705static GSourceFuncs ecore_gsource_funcs = 725static GSourceFuncs ecore_gsource_funcs =
706{ 726{
707 .prepare = _ecore_main_gsource_prepare, 727 .prepare = _ecore_main_gsource_prepare,
708 .check = _ecore_main_gsource_check, 728 .check = _ecore_main_gsource_check,
709 .dispatch = _ecore_main_gsource_dispatch, 729 .dispatch = _ecore_main_gsource_dispatch,
710 .finalize = _ecore_main_gsource_finalize, 730 .finalize = _ecore_main_gsource_finalize,
711}; 731};
@@ -717,7 +737,7 @@ _ecore_main_loop_init(void)
717{ 737{
718 epoll_fd = epoll_create(1); 738 epoll_fd = epoll_create(1);
719 if (epoll_fd < 0) 739 if (epoll_fd < 0)
720 WRN("Failed to create epoll fd!"); 740 WRN("Failed to create epoll fd!");
721 epoll_pid = getpid(); 741 epoll_pid = getpid();
722 742
723 /* add polls on all our file descriptors */ 743 /* add polls on all our file descriptors */
@@ -725,7 +745,7 @@ _ecore_main_loop_init(void)
725 EINA_INLIST_FOREACH(fd_handlers, fdh) 745 EINA_INLIST_FOREACH(fd_handlers, fdh)
726 { 746 {
727 if (fdh->delete_me) 747 if (fdh->delete_me)
728 continue; 748 continue;
729 _ecore_epoll_add(epoll_fd, fdh->fd, 749 _ecore_epoll_add(epoll_fd, fdh->fd,
730 _ecore_poll_events_from_fdh(fdh), fdh); 750 _ecore_poll_events_from_fdh(fdh), fdh);
731 _ecore_main_fdh_poll_add(fdh); 751 _ecore_main_fdh_poll_add(fdh);
@@ -735,34 +755,34 @@ _ecore_main_loop_init(void)
735#ifdef USE_G_MAIN_LOOP 755#ifdef USE_G_MAIN_LOOP
736 ecore_glib_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource)); 756 ecore_glib_source = g_source_new(&ecore_gsource_funcs, sizeof (GSource));
737 if (!ecore_glib_source) 757 if (!ecore_glib_source)
738 CRIT("Failed to create glib source for epoll!"); 758 CRIT("Failed to create glib source for epoll!");
739 else 759 else
740 { 760 {
741 g_source_set_priority(ecore_glib_source, G_PRIORITY_HIGH_IDLE + 20); 761 g_source_set_priority(ecore_glib_source, G_PRIORITY_HIGH_IDLE + 20);
742 if (HAVE_EPOLL && epoll_fd >= 0) 762 if (HAVE_EPOLL && epoll_fd >= 0)
743 { 763 {
744 /* epoll multiplexes fds into the g_main_loop */ 764 /* epoll multiplexes fds into the g_main_loop */
745 ecore_epoll_fd.fd = epoll_fd; 765 ecore_epoll_fd.fd = epoll_fd;
746 ecore_epoll_fd.events = G_IO_IN; 766 ecore_epoll_fd.events = G_IO_IN;
747 ecore_epoll_fd.revents = 0; 767 ecore_epoll_fd.revents = 0;
748 g_source_add_poll(ecore_glib_source, &ecore_epoll_fd); 768 g_source_add_poll(ecore_glib_source, &ecore_epoll_fd);
749 } 769 }
750 770
751 /* timerfd gives us better than millisecond accuracy in g_main_loop */ 771 /* timerfd gives us better than millisecond accuracy in g_main_loop */
752 timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); 772 timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
753 if (timer_fd < 0) 773 if (timer_fd < 0)
754 WRN("failed to create timer fd!"); 774 WRN("failed to create timer fd!");
755 else 775 else
756 { 776 {
757 ecore_timer_fd.fd = timer_fd; 777 ecore_timer_fd.fd = timer_fd;
758 ecore_timer_fd.events = G_IO_IN; 778 ecore_timer_fd.events = G_IO_IN;
759 ecore_timer_fd.revents = 0; 779 ecore_timer_fd.revents = 0;
760 g_source_add_poll(ecore_glib_source, &ecore_timer_fd); 780 g_source_add_poll(ecore_glib_source, &ecore_timer_fd);
761 } 781 }
762 782
763 ecore_glib_source_id = g_source_attach(ecore_glib_source, NULL); 783 ecore_glib_source_id = g_source_attach(ecore_glib_source, NULL);
764 if (ecore_glib_source_id <= 0) 784 if (ecore_glib_source_id <= 0)
765 CRIT("Failed to attach glib source to default context"); 785 CRIT("Failed to attach glib source to default context");
766 } 786 }
767#endif 787#endif
768} 788}
@@ -783,7 +803,7 @@ _ecore_main_loop_shutdown(void)
783 close(epoll_fd); 803 close(epoll_fd);
784 epoll_fd = -1; 804 epoll_fd = -1;
785 } 805 }
786 epoll_pid = 0; 806 epoll_pid = 0;
787 807
788 if (timer_fd >= 0) 808 if (timer_fd >= 0)
789 { 809 {
@@ -951,8 +971,12 @@ ecore_main_loop_select_func_get(void)
951 * @ingroup Ecore_FD_Handler_Group 971 * @ingroup Ecore_FD_Handler_Group
952 */ 972 */
953EAPI Ecore_Fd_Handler * 973EAPI Ecore_Fd_Handler *
954ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, Ecore_Fd_Cb func, const void *data, 974ecore_main_fd_handler_add(int fd,
955 Ecore_Fd_Cb buf_func, const void *buf_data) 975 Ecore_Fd_Handler_Flags flags,
976 Ecore_Fd_Cb func,
977 const void *data,
978 Ecore_Fd_Cb buf_func,
979 const void *buf_data)
956{ 980{
957 Ecore_Fd_Handler *fdh = NULL; 981 Ecore_Fd_Handler *fdh = NULL;
958 982
@@ -984,8 +1008,8 @@ ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, Ecore_Fd_Cb func
984 fd_handlers_with_buffer = eina_list_append(fd_handlers_with_buffer, fdh); 1008 fd_handlers_with_buffer = eina_list_append(fd_handlers_with_buffer, fdh);
985 fdh->buf_data = (void *)buf_data; 1009 fdh->buf_data = (void *)buf_data;
986 fd_handlers = (Ecore_Fd_Handler *) 1010 fd_handlers = (Ecore_Fd_Handler *)
987 eina_inlist_append(EINA_INLIST_GET(fd_handlers), 1011 eina_inlist_append(EINA_INLIST_GET(fd_handlers),
988 EINA_INLIST_GET(fdh)); 1012 EINA_INLIST_GET(fdh));
989unlock: 1013unlock:
990 _ecore_unlock(); 1014 _ecore_unlock();
991 1015
@@ -994,7 +1018,9 @@ unlock:
994 1018
995#ifdef _WIN32 1019#ifdef _WIN32
996EAPI Ecore_Win32_Handler * 1020EAPI Ecore_Win32_Handler *
997ecore_main_win32_handler_add(void *h, Ecore_Win32_Handle_Cb func, const void *data) 1021ecore_main_win32_handler_add(void *h,
1022 Ecore_Win32_Handle_Cb func,
1023 const void *data)
998{ 1024{
999 Ecore_Win32_Handler *wh; 1025 Ecore_Win32_Handler *wh;
1000 1026
@@ -1008,19 +1034,21 @@ ecore_main_win32_handler_add(void *h, Ecore_Win32_Handle_Cb func, const void *da
1008 wh->func = func; 1034 wh->func = func;
1009 wh->data = (void *)data; 1035 wh->data = (void *)data;
1010 win32_handlers = (Ecore_Win32_Handler *) 1036 win32_handlers = (Ecore_Win32_Handler *)
1011 eina_inlist_append(EINA_INLIST_GET(win32_handlers), 1037 eina_inlist_append(EINA_INLIST_GET(win32_handlers),
1012 EINA_INLIST_GET(wh)); 1038 EINA_INLIST_GET(wh));
1013 return wh; 1039 return wh;
1014} 1040}
1041
1015#else 1042#else
1016EAPI Ecore_Win32_Handler * 1043EAPI Ecore_Win32_Handler *
1017ecore_main_win32_handler_add(void *h __UNUSED__, Ecore_Win32_Handle_Cb func __UNUSED__, 1044ecore_main_win32_handler_add(void *h __UNUSED__,
1018 const void *data __UNUSED__) 1045 Ecore_Win32_Handle_Cb func __UNUSED__,
1046 const void *data __UNUSED__)
1019{ 1047{
1020 return NULL; 1048 return NULL;
1021} 1049}
1022#endif
1023 1050
1051#endif
1024 1052
1025/** 1053/**
1026 * Marks an FD handler for deletion. 1054 * Marks an FD handler for deletion.
@@ -1069,12 +1097,14 @@ ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler)
1069 win32_handlers_delete_me = EINA_TRUE; 1097 win32_handlers_delete_me = EINA_TRUE;
1070 return win32_handler->data; 1098 return win32_handler->data;
1071} 1099}
1100
1072#else 1101#else
1073EAPI void * 1102EAPI void *
1074ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler __UNUSED__) 1103ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler __UNUSED__)
1075{ 1104{
1076 return NULL; 1105 return NULL;
1077} 1106}
1107
1078#endif 1108#endif
1079 1109
1080/** 1110/**
@@ -1096,7 +1126,9 @@ ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler __UNUSED__)
1096 * @ingroup Ecore_FD_Handler_Group 1126 * @ingroup Ecore_FD_Handler_Group
1097 */ 1127 */
1098EAPI void 1128EAPI void
1099ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Prep_Cb func, const void *data) 1129ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler,
1130 Ecore_Fd_Prep_Cb func,
1131 const void *data)
1100{ 1132{
1101 _ecore_lock(); 1133 _ecore_lock();
1102 1134
@@ -1109,7 +1141,7 @@ ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, Ecore_F
1109 fd_handler->prep_func = func; 1141 fd_handler->prep_func = func;
1110 fd_handler->prep_data = (void *)data; 1142 fd_handler->prep_data = (void *)data;
1111 if ((!fd_handlers_with_prep) || 1143 if ((!fd_handlers_with_prep) ||
1112 (fd_handlers_with_prep && (!eina_list_data_find(fd_handlers_with_prep, fd_handler)))) 1144 (fd_handlers_with_prep && (!eina_list_data_find(fd_handlers_with_prep, fd_handler))))
1113 /* FIXME: THIS WILL NOT SCALE WITH LOTS OF PREP FUNCTIONS!!! */ 1145 /* FIXME: THIS WILL NOT SCALE WITH LOTS OF PREP FUNCTIONS!!! */
1114 fd_handlers_with_prep = eina_list_append(fd_handlers_with_prep, fd_handler); 1146 fd_handlers_with_prep = eina_list_append(fd_handlers_with_prep, fd_handler);
1115unlock: 1147unlock:
@@ -1151,7 +1183,8 @@ unlock:
1151 * @ingroup Ecore_FD_Handler_Group 1183 * @ingroup Ecore_FD_Handler_Group
1152 */ 1184 */
1153EAPI Eina_Bool 1185EAPI Eina_Bool
1154ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags) 1186ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler,
1187 Ecore_Fd_Handler_Flags flags)
1155{ 1188{
1156 int ret = EINA_FALSE; 1189 int ret = EINA_FALSE;
1157 1190
@@ -1178,7 +1211,8 @@ unlock:
1178 * @ingroup Ecore_FD_Handler_Group 1211 * @ingroup Ecore_FD_Handler_Group
1179 */ 1212 */
1180EAPI void 1213EAPI void
1181ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags) 1214ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler,
1215 Ecore_Fd_Handler_Flags flags)
1182{ 1216{
1183 int ret; 1217 int ret;
1184 1218
@@ -1209,9 +1243,9 @@ _ecore_main_shutdown(void)
1209{ 1243{
1210 if (in_main_loop) 1244 if (in_main_loop)
1211 { 1245 {
1212 ERR("\n" 1246 ERR("\n"
1213 "*** ECORE WARINING: Calling ecore_shutdown() while still in the main loop.\n" 1247 "*** ECORE WARINING: Calling ecore_shutdown() while still in the main loop.\n"
1214 "*** Program may crash or behave strangely now."); 1248 "*** Program may crash or behave strangely now.");
1215 return; 1249 return;
1216 } 1250 }
1217 while (fd_handlers) 1251 while (fd_handlers)
@@ -1219,8 +1253,8 @@ _ecore_main_shutdown(void)
1219 Ecore_Fd_Handler *fdh; 1253 Ecore_Fd_Handler *fdh;
1220 1254
1221 fdh = fd_handlers; 1255 fdh = fd_handlers;
1222 fd_handlers = (Ecore_Fd_Handler *) eina_inlist_remove(EINA_INLIST_GET(fd_handlers), 1256 fd_handlers = (Ecore_Fd_Handler *)eina_inlist_remove(EINA_INLIST_GET(fd_handlers),
1223 EINA_INLIST_GET(fdh)); 1257 EINA_INLIST_GET(fdh));
1224 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE); 1258 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
1225 free(fdh); 1259 free(fdh);
1226 } 1260 }
@@ -1242,8 +1276,8 @@ _ecore_main_shutdown(void)
1242 Ecore_Win32_Handler *wh; 1276 Ecore_Win32_Handler *wh;
1243 1277
1244 wh = win32_handlers; 1278 wh = win32_handlers;
1245 win32_handlers = (Ecore_Win32_Handler *) eina_inlist_remove(EINA_INLIST_GET(win32_handlers), 1279 win32_handlers = (Ecore_Win32_Handler *)eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
1246 EINA_INLIST_GET(wh)); 1280 EINA_INLIST_GET(wh));
1247 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE); 1281 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
1248 free(wh); 1282 free(wh);
1249 } 1283 }
@@ -1282,9 +1316,9 @@ static int
1282_ecore_main_select(double timeout) 1316_ecore_main_select(double timeout)
1283{ 1317{
1284 struct timeval tv, *t; 1318 struct timeval tv, *t;
1285 fd_set rfds, wfds, exfds; 1319 fd_set rfds, wfds, exfds;
1286 int max_fd; 1320 int max_fd;
1287 int ret; 1321 int ret;
1288 1322
1289 t = NULL; 1323 t = NULL;
1290 if ((!ECORE_FINITE(timeout)) || (timeout == 0.0)) /* finite() tests for NaN, too big, too small, and infinity. */ 1324 if ((!ECORE_FINITE(timeout)) || (timeout == 0.0)) /* finite() tests for NaN, too big, too small, and infinity. */
@@ -1342,13 +1376,13 @@ _ecore_main_select(double timeout)
1342 if (fdh->fd > max_fd) max_fd = fdh->fd; 1376 if (fdh->fd > max_fd) max_fd = fdh->fd;
1343 } 1377 }
1344 } 1378 }
1345 } 1379 }
1346 } 1380 }
1347 else 1381 else
1348 { 1382 {
1349 /* polling on the epoll fd will wake when an fd in the epoll set is active */ 1383 /* polling on the epoll fd will wake when an fd in the epoll set is active */
1350 max_fd = _ecore_get_epoll_fd(); 1384 max_fd = _ecore_get_epoll_fd();
1351 FD_SET(max_fd, &rfds); 1385 FD_SET(max_fd, &rfds);
1352 } 1386 }
1353 1387
1354 if (_ecore_signal_count_get()) return -1; 1388 if (_ecore_signal_count_get()) return -1;
@@ -1362,7 +1396,8 @@ _ecore_main_select(double timeout)
1362 { 1396 {
1363#ifndef _WIN32 1397#ifndef _WIN32
1364 if (errno == EINTR) return -1; 1398 if (errno == EINTR) return -1;
1365 else if (errno == EBADF) _ecore_main_fd_handlers_bads_rem(); 1399 else if (errno == EBADF)
1400 _ecore_main_fd_handlers_bads_rem();
1366#endif 1401#endif
1367 } 1402 }
1368 if (ret > 0) 1403 if (ret > 0)
@@ -1396,6 +1431,7 @@ _ecore_main_select(double timeout)
1396 } 1431 }
1397 return 0; 1432 return 0;
1398} 1433}
1434
1399#endif 1435#endif
1400 1436
1401#ifndef _WIN32 1437#ifndef _WIN32
@@ -1410,7 +1446,7 @@ _ecore_main_fd_handlers_bads_rem(void)
1410 ERR("Removing bad fds"); 1446 ERR("Removing bad fds");
1411 for (l = EINA_INLIST_GET(fd_handlers); l; ) 1447 for (l = EINA_INLIST_GET(fd_handlers); l; )
1412 { 1448 {
1413 fdh = (Ecore_Fd_Handler *) l; 1449 fdh = (Ecore_Fd_Handler *)l;
1414 l = l->next; 1450 l = l->next;
1415 errno = 0; 1451 errno = 0;
1416 1452
@@ -1445,7 +1481,7 @@ _ecore_main_fd_handlers_bads_rem(void)
1445 found++; 1481 found++;
1446 } 1482 }
1447 } 1483 }
1448 } 1484 }
1449 if (found == 0) 1485 if (found == 0)
1450 { 1486 {
1451# ifdef HAVE_GLIB 1487# ifdef HAVE_GLIB
@@ -1456,6 +1492,7 @@ _ecore_main_fd_handlers_bads_rem(void)
1456 } 1492 }
1457 _ecore_main_fd_handlers_cleanup(); 1493 _ecore_main_fd_handlers_cleanup();
1458} 1494}
1495
1459# endif 1496# endif
1460#endif 1497#endif
1461 1498
@@ -1481,7 +1518,7 @@ _ecore_main_fd_handlers_cleanup(void)
1481 if (fdh->prep_func && fd_handlers_with_prep) 1518 if (fdh->prep_func && fd_handlers_with_prep)
1482 fd_handlers_with_prep = eina_list_remove(fd_handlers_with_prep, fdh); 1519 fd_handlers_with_prep = eina_list_remove(fd_handlers_with_prep, fdh);
1483 fd_handlers = (Ecore_Fd_Handler *) 1520 fd_handlers = (Ecore_Fd_Handler *)
1484 eina_inlist_remove(EINA_INLIST_GET(fd_handlers), EINA_INLIST_GET(fdh)); 1521 eina_inlist_remove(EINA_INLIST_GET(fd_handlers), EINA_INLIST_GET(fdh));
1485 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE); 1522 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
1486 free(fdh); 1523 free(fdh);
1487 fd_handlers_to_delete = eina_list_remove_list(fd_handlers_to_delete, l); 1524 fd_handlers_to_delete = eina_list_remove_list(fd_handlers_to_delete, l);
@@ -1511,66 +1548,66 @@ _ecore_main_win32_handlers_cleanup(void)
1511 } 1548 }
1512 1549
1513 win32_handlers = (Ecore_Win32_Handler *) 1550 win32_handlers = (Ecore_Win32_Handler *)
1514 eina_inlist_remove(EINA_INLIST_GET(win32_handlers), 1551 eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
1515 EINA_INLIST_GET(wh)); 1552 EINA_INLIST_GET(wh));
1516 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE); 1553 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
1517 free(wh); 1554 free(wh);
1518 } 1555 }
1519 } 1556 }
1520 if (!deleted_in_use) win32_handlers_delete_me = EINA_FALSE; 1557 if (!deleted_in_use) win32_handlers_delete_me = EINA_FALSE;
1521} 1558}
1559
1522#endif 1560#endif
1523 1561
1524static void 1562static void
1525_ecore_main_fd_handlers_call(void) 1563_ecore_main_fd_handlers_call(void)
1526{ 1564{
1527 /* grab a new list */ 1565 /* grab a new list */
1528 if (!fd_handlers_to_call_current) 1566 if (!fd_handlers_to_call_current)
1529 { 1567 {
1530 fd_handlers_to_call_current = fd_handlers_to_call; 1568 fd_handlers_to_call_current = fd_handlers_to_call;
1531 fd_handlers_to_call = NULL; 1569 fd_handlers_to_call = NULL;
1532 } 1570 }
1533 1571
1534 while (fd_handlers_to_call_current) 1572 while (fd_handlers_to_call_current)
1535 { 1573 {
1536 Ecore_Fd_Handler *fdh = fd_handlers_to_call_current; 1574 Ecore_Fd_Handler *fdh = fd_handlers_to_call_current;
1537 1575
1538 if (!fdh->delete_me) 1576 if (!fdh->delete_me)
1539 { 1577 {
1540 if ((fdh->read_active) || 1578 if ((fdh->read_active) ||
1541 (fdh->write_active) || 1579 (fdh->write_active) ||
1542 (fdh->error_active)) 1580 (fdh->error_active))
1543 { 1581 {
1544 fdh->references++; 1582 fdh->references++;
1545 if (!_ecore_call_fd_cb(fdh->func, fdh->data, fdh)) 1583 if (!_ecore_call_fd_cb(fdh->func, fdh->data, fdh))
1546 { 1584 {
1547 if (!fdh->delete_me) 1585 if (!fdh->delete_me)
1548 { 1586 {
1549 fdh->delete_me = EINA_TRUE; 1587 fdh->delete_me = EINA_TRUE;
1550 fd_handlers_to_delete = eina_list_append(fd_handlers_to_delete, fdh); 1588 fd_handlers_to_delete = eina_list_append(fd_handlers_to_delete, fdh);
1551 } 1589 }
1552 1590 }
1553 } 1591 fdh->references--;
1554 fdh->references--; 1592 _ecore_fd_valid();
1555 _ecore_fd_valid(); 1593
1556 1594 fdh->read_active = EINA_FALSE;
1557 fdh->read_active = EINA_FALSE; 1595 fdh->write_active = EINA_FALSE;
1558 fdh->write_active = EINA_FALSE; 1596 fdh->error_active = EINA_FALSE;
1559 fdh->error_active = EINA_FALSE; 1597 }
1560 } 1598 }
1561 } 1599
1562 1600 /* stop when we point to ourselves */
1563 /* stop when we point to ourselves */ 1601 if (fdh->next_ready == fdh)
1564 if (fdh->next_ready == fdh) 1602 {
1565 { 1603 fdh->next_ready = NULL;
1566 fdh->next_ready = NULL; 1604 fd_handlers_to_call_current = NULL;
1567 fd_handlers_to_call_current = NULL; 1605 break;
1568 break; 1606 }
1569 } 1607
1570 1608 fd_handlers_to_call_current = fdh->next_ready;
1571 fd_handlers_to_call_current = fdh->next_ready; 1609 fdh->next_ready = NULL;
1572 fdh->next_ready = NULL; 1610 }
1573 }
1574} 1611}
1575 1612
1576static int 1613static int
@@ -1617,16 +1654,16 @@ static int
1617_ecore_main_loop_spin_core(void) 1654_ecore_main_loop_spin_core(void)
1618{ 1655{
1619 /* as we are spinning we need to update loop time per spin */ 1656 /* as we are spinning we need to update loop time per spin */
1620 _ecore_time_loop_time = ecore_time_get(); 1657 _ecore_time_loop_time = ecore_time_get();
1621 /* call all idlers, which returns false if no more idelrs exist */ 1658 /* call all idlers, which returns false if no more idelrs exist */
1622 if (!_ecore_idler_all_call()) return SPIN_RESTART; 1659 if (!_ecore_idler_all_call()) return SPIN_RESTART;
1623 /* sneaky - drop through or if checks - the first one to succeed 1660 /* sneaky - drop through or if checks - the first one to succeed
1624 * drops through and returns "continue" so further ones dont run */ 1661 * drops through and returns "continue" so further ones dont run */
1625 if ((_ecore_main_select(0.0) > 0) || (_ecore_event_exist()) || 1662 if ((_ecore_main_select(0.0) > 0) || (_ecore_event_exist()) ||
1626 (_ecore_signal_count_get() > 0) || (do_quit)) 1663 (_ecore_signal_count_get() > 0) || (do_quit))
1627 return LOOP_CONTINUE; 1664 return LOOP_CONTINUE;
1628 /* default - spin more */ 1665 /* default - spin more */
1629 return SPIN_MORE; 1666 return SPIN_MORE;
1630} 1667}
1631 1668
1632static int 1669static int
@@ -1634,16 +1671,16 @@ _ecore_main_loop_spin_no_timers(void)
1634{ 1671{
1635 /* if we have idlers we HAVE to spin and handle everything 1672 /* if we have idlers we HAVE to spin and handle everything
1636 * in a polling way - spin in a tight polling loop */ 1673 * in a polling way - spin in a tight polling loop */
1637 for (;;) 1674 for (;; )
1638 { 1675 {
1639 int action = _ecore_main_loop_spin_core(); 1676 int action = _ecore_main_loop_spin_core();
1640 if (action != SPIN_MORE) return action; 1677 if (action != SPIN_MORE) return action;
1641 /* if an idler has added a timer then we need to go through 1678 /* if an idler has added a timer then we need to go through
1642 * the start of the spin cycle again to handle cases properly */ 1679 * the start of the spin cycle again to handle cases properly */
1643 if (_ecore_timers_exists()) return SPIN_RESTART; 1680 if (_ecore_timers_exists()) return SPIN_RESTART;
1644 } 1681 }
1645 /* just contiune handling events etc. */ 1682 /* just contiune handling events etc. */
1646 return LOOP_CONTINUE; 1683 return LOOP_CONTINUE;
1647} 1684}
1648 1685
1649static int 1686static int
@@ -1651,17 +1688,17 @@ _ecore_main_loop_spin_timers(void)
1651{ 1688{
1652 /* if we have idlers we HAVE to spin and handle everything 1689 /* if we have idlers we HAVE to spin and handle everything
1653 * in a polling way - spin in a tight polling loop */ 1690 * in a polling way - spin in a tight polling loop */
1654 for (;;) 1691 for (;; )
1655 { 1692 {
1656 int action = _ecore_main_loop_spin_core(); 1693 int action = _ecore_main_loop_spin_core();
1657 if (action != SPIN_MORE) return action; 1694 if (action != SPIN_MORE) return action;
1658 /* if next timer expires now or in the past - stop spinning and 1695 /* if next timer expires now or in the past - stop spinning and
1659 * continue the mainloop walk as our "select" timeout has 1696 * continue the mainloop walk as our "select" timeout has
1660 * expired now */ 1697 * expired now */
1661 if (_ecore_timer_next_get() <= 0.0) return LOOP_CONTINUE; 1698 if (_ecore_timer_next_get() <= 0.0) return LOOP_CONTINUE;
1662 } 1699 }
1663 /* just contiune handling events etc. */ 1700 /* just contiune handling events etc. */
1664 return LOOP_CONTINUE; 1701 return LOOP_CONTINUE;
1665} 1702}
1666 1703
1667static void 1704static void
@@ -1696,40 +1733,40 @@ _ecore_main_loop_iterate_internal(int once_only)
1696 if (_ecore_event_exist()) 1733 if (_ecore_event_exist())
1697 { 1734 {
1698 /* but first conceptually enter an idle state */ 1735 /* but first conceptually enter an idle state */
1699 _ecore_idle_enterer_call(); 1736 _ecore_idle_enterer_call();
1700 _ecore_throttle(); 1737 _ecore_throttle();
1701 /* now quickly poll to see which input fd's are active */ 1738 /* now quickly poll to see which input fd's are active */
1702 _ecore_main_select(0.0); 1739 _ecore_main_select(0.0);
1703 /* allow newly queued timers to expire from now on */ 1740 /* allow newly queued timers to expire from now on */
1704 _ecore_timer_enable_new(); 1741 _ecore_timer_enable_new();
1705 /* go straight to processing the events we had queued */ 1742 /* go straight to processing the events we had queued */
1706 goto process_all; 1743 goto process_all;
1707 } 1744 }
1708 1745
1709 if (once_only) 1746 if (once_only)
1710 { 1747 {
1711 /* in once_only mode we should quickly poll for inputs, signals 1748 /* in once_only mode we should quickly poll for inputs, signals
1712 * if we got any events or signals, allow new timers to process. 1749 * if we got any events or signals, allow new timers to process.
1713 * use bitwise or to force both conditions to be tested and 1750 * use bitwise or to force both conditions to be tested and
1714 * merged together */ 1751 * merged together */
1715 if (_ecore_main_select(0.0) | _ecore_signal_count_get()) 1752 if (_ecore_main_select(0.0) | _ecore_signal_count_get())
1716 { 1753 {
1717 _ecore_timer_enable_new(); 1754 _ecore_timer_enable_new();
1718 goto process_all; 1755 goto process_all;
1719 } 1756 }
1720 } 1757 }
1721 else 1758 else
1722 { 1759 {
1723 /* call idle enterers ... */ 1760 /* call idle enterers ... */
1724 _ecore_idle_enterer_call(); 1761 _ecore_idle_enterer_call();
1725 _ecore_throttle(); 1762 _ecore_throttle();
1726 } 1763 }
1727 1764
1728 /* if these calls caused any buffered events to appear - deal with them */ 1765 /* if these calls caused any buffered events to appear - deal with them */
1729 if (fd_handlers_with_buffer) 1766 if (fd_handlers_with_buffer)
1730 _ecore_main_fd_handlers_buf_call(); 1767 _ecore_main_fd_handlers_buf_call();
1731 1768
1732 /* if there are any (buffered fd handling may generate them) 1769 /* if there are any (buffered fd handling may generate them)
1733 * then jump to processing them */ 1770 * then jump to processing them */
1734 if (_ecore_event_exist()) 1771 if (_ecore_event_exist())
1735 { 1772 {
@@ -1737,18 +1774,18 @@ _ecore_main_loop_iterate_internal(int once_only)
1737 _ecore_timer_enable_new(); 1774 _ecore_timer_enable_new();
1738 goto process_all; 1775 goto process_all;
1739 } 1776 }
1740 1777
1741 if (once_only) 1778 if (once_only)
1742 { 1779 {
1743 /* in once_only mode enter idle here instead and then return */ 1780 /* in once_only mode enter idle here instead and then return */
1744 _ecore_idle_enterer_call(); 1781 _ecore_idle_enterer_call();
1745 _ecore_throttle(); 1782 _ecore_throttle();
1746 _ecore_timer_enable_new(); 1783 _ecore_timer_enable_new();
1747 goto done; 1784 goto done;
1748 } 1785 }
1749 1786
1750 _ecore_fps_marker_1(); 1787 _ecore_fps_marker_1();
1751 1788
1752 /* start of the sleeping or looping section */ 1789 /* start of the sleeping or looping section */
1753start_loop: /***************************************************************/ 1790start_loop: /***************************************************************/
1754 /* any timers re-added as a result of these are allowed to go */ 1791 /* any timers re-added as a result of these are allowed to go */
@@ -1762,30 +1799,29 @@ start_loop: /***************************************************************/
1762 if (!_ecore_event_exist()) 1799 if (!_ecore_event_exist())
1763 { 1800 {
1764 /* init flags */ 1801 /* init flags */
1765 next_time = _ecore_timer_next_get(); 1802 next_time = _ecore_timer_next_get();
1766 /* no idlers */ 1803 /* no idlers */
1767 if (!_ecore_idler_exist()) 1804 if (!_ecore_idler_exist())
1768 { 1805 {
1769 /* sleep until timeout or forever (-1.0) waiting for on fds */ 1806 /* sleep until timeout or forever (-1.0) waiting for on fds */
1770 _ecore_main_select(next_time); 1807 _ecore_main_select(next_time);
1771 } 1808 }
1772 else 1809 else
1773 { 1810 {
1774 int action = LOOP_CONTINUE; 1811 int action = LOOP_CONTINUE;
1775 1812
1776 /* no timers - spin */ 1813 /* no timers - spin */
1777 if (next_time < 0) action = _ecore_main_loop_spin_no_timers(); 1814 if (next_time < 0) action = _ecore_main_loop_spin_no_timers();
1778 /* timers - spin */ 1815 /* timers - spin */
1779 else action = _ecore_main_loop_spin_timers(); 1816 else action = _ecore_main_loop_spin_timers();
1780 if (action == SPIN_RESTART) goto start_loop; 1817 if (action == SPIN_RESTART) goto start_loop;
1781 } 1818 }
1782 } 1819 }
1783 _ecore_fps_marker_2(); 1820 _ecore_fps_marker_2();
1784 1821
1785
1786 /* actually wake up and deal with input, events etc. */ 1822 /* actually wake up and deal with input, events etc. */
1787process_all: /***********************************************************/ 1823process_all: /***********************************************************/
1788 1824
1789 /* we came out of our "wait state" so idle has exited */ 1825 /* we came out of our "wait state" so idle has exited */
1790 if (!once_only) _ecore_idle_exiter_call(); 1826 if (!once_only) _ecore_idle_exiter_call();
1791 /* call the fd handler per fd that became alive... */ 1827 /* call the fd handler per fd that became alive... */
@@ -1802,32 +1838,36 @@ process_all: /***********************************************************/
1802 if (once_only) 1838 if (once_only)
1803 { 1839 {
1804 /* if in once_only mode handle idle exiting */ 1840 /* if in once_only mode handle idle exiting */
1805 _ecore_idle_enterer_call(); 1841 _ecore_idle_enterer_call();
1806 _ecore_throttle(); 1842 _ecore_throttle();
1807 } 1843 }
1808 1844
1809done: /*******************************************************************/ 1845done: /*******************************************************************/
1810 in_main_loop--; 1846 in_main_loop--;
1811} 1847}
1848
1812#endif 1849#endif
1813 1850
1814#ifdef _WIN32 1851#ifdef _WIN32
1815static int 1852static int
1816_ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds, 1853_ecore_main_win32_select(int nfds __UNUSED__,
1817 fd_set *exceptfds, struct timeval *tv) 1854 fd_set *readfds,
1855 fd_set *writefds,
1856 fd_set *exceptfds,
1857 struct timeval *tv)
1818{ 1858{
1819 HANDLE objects[MAXIMUM_WAIT_OBJECTS]; 1859 HANDLE objects[MAXIMUM_WAIT_OBJECTS];
1820 int sockets[MAXIMUM_WAIT_OBJECTS]; 1860 int sockets[MAXIMUM_WAIT_OBJECTS];
1821 Ecore_Fd_Handler *fdh; 1861 Ecore_Fd_Handler *fdh;
1822 Ecore_Win32_Handler *wh; 1862 Ecore_Win32_Handler *wh;
1823 unsigned int objects_nbr = 0; 1863 unsigned int objects_nbr = 0;
1824 unsigned int handles_nbr = 0; 1864 unsigned int handles_nbr = 0;
1825 unsigned int events_nbr = 0; 1865 unsigned int events_nbr = 0;
1826 DWORD result; 1866 DWORD result;
1827 DWORD timeout; 1867 DWORD timeout;
1828 MSG msg; 1868 MSG msg;
1829 unsigned int i; 1869 unsigned int i;
1830 int res; 1870 int res;
1831 1871
1832 /* Create an event object per socket */ 1872 /* Create an event object per socket */
1833 EINA_INLIST_FOREACH(fd_handlers, fdh) 1873 EINA_INLIST_FOREACH(fd_handlers, fdh)
@@ -1898,7 +1938,7 @@ _ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds,
1898 else if (result == WAIT_TIMEOUT) 1938 else if (result == WAIT_TIMEOUT)
1899 { 1939 {
1900 /* ERR("time out\n"); */ 1940 /* ERR("time out\n"); */
1901 res = 0; 1941 res = 0;
1902 } 1942 }
1903 else if (result == (WAIT_OBJECT_0 + objects_nbr)) 1943 else if (result == (WAIT_OBJECT_0 + objects_nbr))
1904 { 1944 {
@@ -1917,11 +1957,11 @@ _ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds,
1917 WSAEnumNetworkEvents(sockets[result], objects[result], &network_event); 1957 WSAEnumNetworkEvents(sockets[result], objects[result], &network_event);
1918 1958
1919 if (network_event.lNetworkEvents & FD_READ) 1959 if (network_event.lNetworkEvents & FD_READ)
1920 FD_SET(sockets[result], readfds); 1960 FD_SET(sockets[result], readfds);
1921 if (network_event.lNetworkEvents & FD_WRITE) 1961 if (network_event.lNetworkEvents & FD_WRITE)
1922 FD_SET(sockets[result], writefds); 1962 FD_SET(sockets[result], writefds);
1923 if (network_event.lNetworkEvents & FD_OOB) 1963 if (network_event.lNetworkEvents & FD_OOB)
1924 FD_SET(sockets[result], exceptfds); 1964 FD_SET(sockets[result], exceptfds);
1925 1965
1926 res = 1; 1966 res = 1;
1927 } 1967 }
@@ -1931,12 +1971,12 @@ _ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds,
1931 if (!win32_handler_current) 1971 if (!win32_handler_current)
1932 { 1972 {
1933 /* regular main loop, start from head */ 1973 /* regular main loop, start from head */
1934 win32_handler_current = win32_handlers; 1974 win32_handler_current = win32_handlers;
1935 } 1975 }
1936 else 1976 else
1937 { 1977 {
1938 /* recursive main loop, continue from where we were */ 1978 /* recursive main loop, continue from where we were */
1939 win32_handler_current = (Ecore_Win32_Handler *)EINA_INLIST_GET(win32_handler_current)->next; 1979 win32_handler_current = (Ecore_Win32_Handler *)EINA_INLIST_GET(win32_handler_current)->next;
1940 } 1980 }
1941 1981
1942 while (win32_handler_current) 1982 while (win32_handler_current)
@@ -1972,4 +2012,5 @@ _ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds,
1972 2012
1973 return res; 2013 return res;
1974} 2014}
2015
1975#endif 2016#endif