… | |
… | |
35 | |
35 | |
36 | #ifndef EV_STANDALONE |
36 | #ifndef EV_STANDALONE |
37 | # include "config.h" |
37 | # include "config.h" |
38 | |
38 | |
39 | # if HAVE_CLOCK_GETTIME |
39 | # if HAVE_CLOCK_GETTIME |
|
|
40 | # ifndef EV_USE_MONOTONIC |
40 | # define EV_USE_MONOTONIC 1 |
41 | # define EV_USE_MONOTONIC 1 |
|
|
42 | # endif |
|
|
43 | # ifndef EV_USE_REALTIME |
41 | # define EV_USE_REALTIME 1 |
44 | # define EV_USE_REALTIME 1 |
|
|
45 | # endif |
42 | # endif |
46 | # endif |
43 | |
47 | |
44 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
48 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
45 | # define EV_USE_SELECT 1 |
49 | # define EV_USE_SELECT 1 |
46 | # endif |
50 | # endif |
47 | |
51 | |
48 | # if HAVE_POLL && HAVE_POLL_H |
52 | # if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) |
49 | # define EV_USE_POLL 1 |
53 | # define EV_USE_POLL 1 |
50 | # endif |
54 | # endif |
51 | |
55 | |
52 | # if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
56 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) |
53 | # define EV_USE_EPOLL 1 |
57 | # define EV_USE_EPOLL 1 |
54 | # endif |
58 | # endif |
55 | |
59 | |
56 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
57 | # define EV_USE_KQUEUE 1 |
61 | # define EV_USE_KQUEUE 1 |
58 | # endif |
62 | # endif |
59 | |
63 | |
60 | #endif |
64 | #endif |
61 | |
65 | |
… | |
… | |
71 | #include <sys/types.h> |
75 | #include <sys/types.h> |
72 | #include <time.h> |
76 | #include <time.h> |
73 | |
77 | |
74 | #include <signal.h> |
78 | #include <signal.h> |
75 | |
79 | |
76 | #ifndef WIN32 |
80 | #ifndef _WIN32 |
77 | # include <unistd.h> |
81 | # include <unistd.h> |
78 | # include <sys/time.h> |
82 | # include <sys/time.h> |
79 | # include <sys/wait.h> |
83 | # include <sys/wait.h> |
|
|
84 | #else |
|
|
85 | # define WIN32_LEAN_AND_MEAN |
|
|
86 | # include <windows.h> |
|
|
87 | # ifndef EV_SELECT_IS_WINSOCKET |
|
|
88 | # define EV_SELECT_IS_WINSOCKET 1 |
80 | #endif |
89 | # endif |
|
|
90 | #endif |
|
|
91 | |
81 | /**/ |
92 | /**/ |
82 | |
93 | |
83 | #ifndef EV_USE_MONOTONIC |
94 | #ifndef EV_USE_MONOTONIC |
84 | # define EV_USE_MONOTONIC 1 |
95 | # define EV_USE_MONOTONIC 1 |
85 | #endif |
96 | #endif |
86 | |
97 | |
87 | #ifndef EV_USE_SELECT |
98 | #ifndef EV_USE_SELECT |
88 | # define EV_USE_SELECT 1 |
99 | # define EV_USE_SELECT 1 |
|
|
100 | # define EV_SELECT_USE_FD_SET 1 |
89 | #endif |
101 | #endif |
90 | |
102 | |
91 | #ifndef EV_USE_POLL |
103 | #ifndef EV_USE_POLL |
92 | # define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ |
104 | # ifdef _WIN32 |
|
|
105 | # define EV_USE_POLL 0 |
|
|
106 | # else |
|
|
107 | # define EV_USE_POLL 1 |
|
|
108 | # endif |
93 | #endif |
109 | #endif |
94 | |
110 | |
95 | #ifndef EV_USE_EPOLL |
111 | #ifndef EV_USE_EPOLL |
96 | # define EV_USE_EPOLL 0 |
112 | # define EV_USE_EPOLL 0 |
97 | #endif |
113 | #endif |
98 | |
114 | |
99 | #ifndef EV_USE_KQUEUE |
115 | #ifndef EV_USE_KQUEUE |
100 | # define EV_USE_KQUEUE 0 |
116 | # define EV_USE_KQUEUE 0 |
101 | #endif |
117 | #endif |
102 | |
118 | |
103 | #ifndef EV_USE_WIN32 |
|
|
104 | # ifdef WIN32 |
|
|
105 | # define EV_USE_WIN32 0 /* it does not exist, use select */ |
|
|
106 | # undef EV_USE_SELECT |
|
|
107 | # define EV_USE_SELECT 1 |
|
|
108 | # else |
|
|
109 | # define EV_USE_WIN32 0 |
|
|
110 | # endif |
|
|
111 | #endif |
|
|
112 | |
|
|
113 | #ifndef EV_USE_REALTIME |
119 | #ifndef EV_USE_REALTIME |
114 | # define EV_USE_REALTIME 1 |
120 | # define EV_USE_REALTIME 1 |
115 | #endif |
121 | #endif |
116 | |
122 | |
117 | /**/ |
123 | /**/ |
|
|
124 | |
|
|
125 | /* darwin simply cannot be helped */ |
|
|
126 | #ifdef __APPLE__ |
|
|
127 | # undef EV_USE_POLL |
|
|
128 | # undef EV_USE_KQUEUE |
|
|
129 | #endif |
118 | |
130 | |
119 | #ifndef CLOCK_MONOTONIC |
131 | #ifndef CLOCK_MONOTONIC |
120 | # undef EV_USE_MONOTONIC |
132 | # undef EV_USE_MONOTONIC |
121 | # define EV_USE_MONOTONIC 0 |
133 | # define EV_USE_MONOTONIC 0 |
122 | #endif |
134 | #endif |
123 | |
135 | |
124 | #ifndef CLOCK_REALTIME |
136 | #ifndef CLOCK_REALTIME |
125 | # undef EV_USE_REALTIME |
137 | # undef EV_USE_REALTIME |
126 | # define EV_USE_REALTIME 0 |
138 | # define EV_USE_REALTIME 0 |
|
|
139 | #endif |
|
|
140 | |
|
|
141 | #if EV_SELECT_IS_WINSOCKET |
|
|
142 | # include <winsock.h> |
127 | #endif |
143 | #endif |
128 | |
144 | |
129 | /**/ |
145 | /**/ |
130 | |
146 | |
131 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
147 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
… | |
… | |
151 | #define expect_true(expr) expect ((expr) != 0, 1) |
167 | #define expect_true(expr) expect ((expr) != 0, 1) |
152 | |
168 | |
153 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
169 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
154 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
170 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
155 | |
171 | |
|
|
172 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
|
|
173 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
174 | |
156 | typedef struct ev_watcher *W; |
175 | typedef struct ev_watcher *W; |
157 | typedef struct ev_watcher_list *WL; |
176 | typedef struct ev_watcher_list *WL; |
158 | typedef struct ev_watcher_time *WT; |
177 | typedef struct ev_watcher_time *WT; |
159 | |
178 | |
160 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
179 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
161 | |
180 | |
|
|
181 | #ifdef _WIN32 |
162 | #include "ev_win32.c" |
182 | # include "ev_win32.c" |
|
|
183 | #endif |
163 | |
184 | |
164 | /*****************************************************************************/ |
185 | /*****************************************************************************/ |
165 | |
186 | |
166 | static void (*syserr_cb)(const char *msg); |
187 | static void (*syserr_cb)(const char *msg); |
167 | |
188 | |
… | |
… | |
214 | typedef struct |
235 | typedef struct |
215 | { |
236 | { |
216 | WL head; |
237 | WL head; |
217 | unsigned char events; |
238 | unsigned char events; |
218 | unsigned char reify; |
239 | unsigned char reify; |
|
|
240 | #if EV_SELECT_IS_WINSOCKET |
|
|
241 | SOCKET handle; |
|
|
242 | #endif |
219 | } ANFD; |
243 | } ANFD; |
220 | |
244 | |
221 | typedef struct |
245 | typedef struct |
222 | { |
246 | { |
223 | W w; |
247 | W w; |
… | |
… | |
227 | #if EV_MULTIPLICITY |
251 | #if EV_MULTIPLICITY |
228 | |
252 | |
229 | struct ev_loop |
253 | struct ev_loop |
230 | { |
254 | { |
231 | ev_tstamp ev_rt_now; |
255 | ev_tstamp ev_rt_now; |
|
|
256 | #define ev_rt_now ((loop)->ev_rt_now) |
232 | #define VAR(name,decl) decl; |
257 | #define VAR(name,decl) decl; |
233 | #include "ev_vars.h" |
258 | #include "ev_vars.h" |
234 | #undef VAR |
259 | #undef VAR |
235 | }; |
260 | }; |
236 | #include "ev_wrap.h" |
261 | #include "ev_wrap.h" |
… | |
… | |
249 | |
274 | |
250 | #endif |
275 | #endif |
251 | |
276 | |
252 | /*****************************************************************************/ |
277 | /*****************************************************************************/ |
253 | |
278 | |
254 | inline ev_tstamp |
279 | ev_tstamp |
255 | ev_time (void) |
280 | ev_time (void) |
256 | { |
281 | { |
257 | #if EV_USE_REALTIME |
282 | #if EV_USE_REALTIME |
258 | struct timespec ts; |
283 | struct timespec ts; |
259 | clock_gettime (CLOCK_REALTIME, &ts); |
284 | clock_gettime (CLOCK_REALTIME, &ts); |
… | |
… | |
286 | { |
311 | { |
287 | return ev_rt_now; |
312 | return ev_rt_now; |
288 | } |
313 | } |
289 | #endif |
314 | #endif |
290 | |
315 | |
291 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
316 | #define array_roundsize(type,n) (((n) | 4) & ~3) |
292 | |
317 | |
293 | #define array_needsize(type,base,cur,cnt,init) \ |
318 | #define array_needsize(type,base,cur,cnt,init) \ |
294 | if (expect_false ((cnt) > cur)) \ |
319 | if (expect_false ((cnt) > cur)) \ |
295 | { \ |
320 | { \ |
296 | int newcnt = cur; \ |
321 | int newcnt = cur; \ |
… | |
… | |
311 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
336 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
312 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
337 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
313 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
338 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
314 | } |
339 | } |
315 | |
340 | |
316 | /* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ |
|
|
317 | /* bringing us everlasting joy in form of stupid extra macros that are not required in C */ |
|
|
318 | #define array_free_microshit(stem) \ |
|
|
319 | ev_free (stem ## s); stem ## cnt = stem ## max = 0; |
|
|
320 | |
|
|
321 | #define array_free(stem, idx) \ |
341 | #define array_free(stem, idx) \ |
322 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
342 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
323 | |
343 | |
324 | /*****************************************************************************/ |
344 | /*****************************************************************************/ |
325 | |
345 | |
… | |
… | |
346 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
366 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
347 | return; |
367 | return; |
348 | } |
368 | } |
349 | |
369 | |
350 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
370 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
351 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); |
371 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
352 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
372 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
353 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
373 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
354 | } |
374 | } |
355 | |
375 | |
356 | static void |
376 | static void |
… | |
… | |
399 | int events = 0; |
419 | int events = 0; |
400 | |
420 | |
401 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
421 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
402 | events |= w->events; |
422 | events |= w->events; |
403 | |
423 | |
|
|
424 | #if EV_SELECT_IS_WINSOCKET |
|
|
425 | if (events) |
|
|
426 | { |
|
|
427 | unsigned long argp; |
|
|
428 | anfd->handle = _get_osfhandle (fd); |
|
|
429 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
|
|
430 | } |
|
|
431 | #endif |
|
|
432 | |
404 | anfd->reify = 0; |
433 | anfd->reify = 0; |
405 | |
434 | |
406 | method_modify (EV_A_ fd, anfd->events, events); |
435 | method_modify (EV_A_ fd, anfd->events, events); |
407 | anfd->events = events; |
436 | anfd->events = events; |
408 | } |
437 | } |
… | |
… | |
417 | return; |
446 | return; |
418 | |
447 | |
419 | anfds [fd].reify = 1; |
448 | anfds [fd].reify = 1; |
420 | |
449 | |
421 | ++fdchangecnt; |
450 | ++fdchangecnt; |
422 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); |
451 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
423 | fdchanges [fdchangecnt - 1] = fd; |
452 | fdchanges [fdchangecnt - 1] = fd; |
424 | } |
453 | } |
425 | |
454 | |
426 | static void |
455 | static void |
427 | fd_kill (EV_P_ int fd) |
456 | fd_kill (EV_P_ int fd) |
… | |
… | |
436 | } |
465 | } |
437 | |
466 | |
438 | static int |
467 | static int |
439 | fd_valid (int fd) |
468 | fd_valid (int fd) |
440 | { |
469 | { |
441 | #ifdef WIN32 |
470 | #ifdef _WIN32 |
442 | return !!win32_get_osfhandle (fd); |
471 | return _get_osfhandle (fd) != -1; |
443 | #else |
472 | #else |
444 | return fcntl (fd, F_GETFD) != -1; |
473 | return fcntl (fd, F_GETFD) != -1; |
445 | #endif |
474 | #endif |
446 | } |
475 | } |
447 | |
476 | |
… | |
… | |
528 | heap [k] = w; |
557 | heap [k] = w; |
529 | ((W)heap [k])->active = k + 1; |
558 | ((W)heap [k])->active = k + 1; |
530 | } |
559 | } |
531 | |
560 | |
532 | inline void |
561 | inline void |
533 | adjustheap (WT *heap, int N, int k, ev_tstamp at) |
562 | adjustheap (WT *heap, int N, int k) |
534 | { |
563 | { |
535 | ev_tstamp old_at = heap [k]->at; |
564 | upheap (heap, k); |
536 | heap [k]->at = at; |
|
|
537 | |
|
|
538 | if (old_at < at) |
|
|
539 | downheap (heap, N, k); |
565 | downheap (heap, N, k); |
540 | else |
|
|
541 | upheap (heap, k); |
|
|
542 | } |
566 | } |
543 | |
567 | |
544 | /*****************************************************************************/ |
568 | /*****************************************************************************/ |
545 | |
569 | |
546 | typedef struct |
570 | typedef struct |
… | |
… | |
569 | } |
593 | } |
570 | |
594 | |
571 | static void |
595 | static void |
572 | sighandler (int signum) |
596 | sighandler (int signum) |
573 | { |
597 | { |
574 | #if WIN32 |
598 | #if _WIN32 |
575 | signal (signum, sighandler); |
599 | signal (signum, sighandler); |
576 | #endif |
600 | #endif |
577 | |
601 | |
578 | signals [signum - 1].gotsig = 1; |
602 | signals [signum - 1].gotsig = 1; |
579 | |
603 | |
580 | if (!gotsig) |
604 | if (!gotsig) |
581 | { |
605 | { |
582 | int old_errno = errno; |
606 | int old_errno = errno; |
583 | gotsig = 1; |
607 | gotsig = 1; |
584 | #ifdef WIN32 |
|
|
585 | send (sigpipe [1], &signum, 1, MSG_DONTWAIT); |
|
|
586 | #else |
|
|
587 | write (sigpipe [1], &signum, 1); |
608 | write (sigpipe [1], &signum, 1); |
588 | #endif |
|
|
589 | errno = old_errno; |
609 | errno = old_errno; |
590 | } |
610 | } |
591 | } |
611 | } |
592 | |
612 | |
593 | void |
613 | void |
… | |
… | |
613 | static void |
633 | static void |
614 | sigcb (EV_P_ struct ev_io *iow, int revents) |
634 | sigcb (EV_P_ struct ev_io *iow, int revents) |
615 | { |
635 | { |
616 | int signum; |
636 | int signum; |
617 | |
637 | |
618 | #ifdef WIN32 |
|
|
619 | recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); |
|
|
620 | #else |
|
|
621 | read (sigpipe [0], &revents, 1); |
638 | read (sigpipe [0], &revents, 1); |
622 | #endif |
|
|
623 | gotsig = 0; |
639 | gotsig = 0; |
624 | |
640 | |
625 | for (signum = signalmax; signum--; ) |
641 | for (signum = signalmax; signum--; ) |
626 | if (signals [signum].gotsig) |
642 | if (signals [signum].gotsig) |
627 | ev_feed_signal_event (EV_A_ signum + 1); |
643 | ev_feed_signal_event (EV_A_ signum + 1); |
628 | } |
644 | } |
629 | |
645 | |
|
|
646 | inline void |
|
|
647 | fd_intern (int fd) |
|
|
648 | { |
|
|
649 | #ifdef _WIN32 |
|
|
650 | int arg = 1; |
|
|
651 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
|
|
652 | #else |
|
|
653 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
654 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
655 | #endif |
|
|
656 | } |
|
|
657 | |
630 | static void |
658 | static void |
631 | siginit (EV_P) |
659 | siginit (EV_P) |
632 | { |
660 | { |
633 | #ifndef WIN32 |
661 | fd_intern (sigpipe [0]); |
634 | fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); |
662 | fd_intern (sigpipe [1]); |
635 | fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); |
|
|
636 | |
|
|
637 | /* rather than sort out wether we really need nb, set it */ |
|
|
638 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
|
|
639 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
|
|
640 | #endif |
|
|
641 | |
663 | |
642 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
664 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
643 | ev_io_start (EV_A_ &sigev); |
665 | ev_io_start (EV_A_ &sigev); |
644 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
666 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
645 | } |
667 | } |
646 | |
668 | |
647 | /*****************************************************************************/ |
669 | /*****************************************************************************/ |
648 | |
670 | |
649 | static struct ev_child *childs [PID_HASHSIZE]; |
671 | static struct ev_child *childs [PID_HASHSIZE]; |
650 | |
672 | |
651 | #ifndef WIN32 |
673 | #ifndef _WIN32 |
652 | |
674 | |
653 | static struct ev_signal childev; |
675 | static struct ev_signal childev; |
654 | |
676 | |
655 | #ifndef WCONTINUED |
677 | #ifndef WCONTINUED |
656 | # define WCONTINUED 0 |
678 | # define WCONTINUED 0 |
… | |
… | |
717 | |
739 | |
718 | /* return true if we are running with elevated privileges and should ignore env variables */ |
740 | /* return true if we are running with elevated privileges and should ignore env variables */ |
719 | static int |
741 | static int |
720 | enable_secure (void) |
742 | enable_secure (void) |
721 | { |
743 | { |
722 | #ifdef WIN32 |
744 | #ifdef _WIN32 |
723 | return 0; |
745 | return 0; |
724 | #else |
746 | #else |
725 | return getuid () != geteuid () |
747 | return getuid () != geteuid () |
726 | || getgid () != getegid (); |
748 | || getgid () != getegid (); |
727 | #endif |
749 | #endif |
728 | } |
750 | } |
729 | |
751 | |
730 | int |
752 | unsigned int |
731 | ev_method (EV_P) |
753 | ev_method (EV_P) |
732 | { |
754 | { |
733 | return method; |
755 | return method; |
734 | } |
756 | } |
735 | |
757 | |
736 | static void |
758 | static void |
737 | loop_init (EV_P_ int methods) |
759 | loop_init (EV_P_ unsigned int flags) |
738 | { |
760 | { |
739 | if (!method) |
761 | if (!method) |
740 | { |
762 | { |
741 | #if EV_USE_MONOTONIC |
763 | #if EV_USE_MONOTONIC |
742 | { |
764 | { |
… | |
… | |
749 | ev_rt_now = ev_time (); |
771 | ev_rt_now = ev_time (); |
750 | mn_now = get_clock (); |
772 | mn_now = get_clock (); |
751 | now_floor = mn_now; |
773 | now_floor = mn_now; |
752 | rtmn_diff = ev_rt_now - mn_now; |
774 | rtmn_diff = ev_rt_now - mn_now; |
753 | |
775 | |
754 | if (methods == EVMETHOD_AUTO) |
776 | if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) |
755 | if (!enable_secure () && getenv ("LIBEV_METHODS")) |
|
|
756 | methods = atoi (getenv ("LIBEV_METHODS")); |
777 | flags = atoi (getenv ("LIBEV_FLAGS")); |
757 | else |
778 | |
758 | methods = EVMETHOD_ANY; |
779 | if (!(flags & 0x0000ffff)) |
|
|
780 | flags |= 0x0000ffff; |
759 | |
781 | |
760 | method = 0; |
782 | method = 0; |
761 | #if EV_USE_WIN32 |
|
|
762 | if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods); |
|
|
763 | #endif |
|
|
764 | #if EV_USE_KQUEUE |
783 | #if EV_USE_KQUEUE |
765 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
784 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
766 | #endif |
785 | #endif |
767 | #if EV_USE_EPOLL |
786 | #if EV_USE_EPOLL |
768 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
787 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
769 | #endif |
788 | #endif |
770 | #if EV_USE_POLL |
789 | #if EV_USE_POLL |
771 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
790 | if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); |
772 | #endif |
791 | #endif |
773 | #if EV_USE_SELECT |
792 | #if EV_USE_SELECT |
774 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
793 | if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); |
775 | #endif |
794 | #endif |
776 | |
795 | |
777 | ev_init (&sigev, sigcb); |
796 | ev_init (&sigev, sigcb); |
778 | ev_set_priority (&sigev, EV_MAXPRI); |
797 | ev_set_priority (&sigev, EV_MAXPRI); |
779 | } |
798 | } |
… | |
… | |
782 | void |
801 | void |
783 | loop_destroy (EV_P) |
802 | loop_destroy (EV_P) |
784 | { |
803 | { |
785 | int i; |
804 | int i; |
786 | |
805 | |
787 | #if EV_USE_WIN32 |
|
|
788 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
|
|
789 | #endif |
|
|
790 | #if EV_USE_KQUEUE |
806 | #if EV_USE_KQUEUE |
791 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
807 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
792 | #endif |
808 | #endif |
793 | #if EV_USE_EPOLL |
809 | #if EV_USE_EPOLL |
794 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
810 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
… | |
… | |
802 | |
818 | |
803 | for (i = NUMPRI; i--; ) |
819 | for (i = NUMPRI; i--; ) |
804 | array_free (pending, [i]); |
820 | array_free (pending, [i]); |
805 | |
821 | |
806 | /* have to use the microsoft-never-gets-it-right macro */ |
822 | /* have to use the microsoft-never-gets-it-right macro */ |
807 | array_free_microshit (fdchange); |
823 | array_free (fdchange, EMPTY0); |
808 | array_free_microshit (timer); |
824 | array_free (timer, EMPTY0); |
809 | array_free_microshit (periodic); |
825 | #if EV_PERIODICS |
810 | array_free_microshit (idle); |
826 | array_free (periodic, EMPTY0); |
811 | array_free_microshit (prepare); |
827 | #endif |
812 | array_free_microshit (check); |
828 | array_free (idle, EMPTY0); |
|
|
829 | array_free (prepare, EMPTY0); |
|
|
830 | array_free (check, EMPTY0); |
813 | |
831 | |
814 | method = 0; |
832 | method = 0; |
815 | } |
833 | } |
816 | |
834 | |
817 | static void |
835 | static void |
… | |
… | |
842 | postfork = 0; |
860 | postfork = 0; |
843 | } |
861 | } |
844 | |
862 | |
845 | #if EV_MULTIPLICITY |
863 | #if EV_MULTIPLICITY |
846 | struct ev_loop * |
864 | struct ev_loop * |
847 | ev_loop_new (int methods) |
865 | ev_loop_new (unsigned int flags) |
848 | { |
866 | { |
849 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
867 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
850 | |
868 | |
851 | memset (loop, 0, sizeof (struct ev_loop)); |
869 | memset (loop, 0, sizeof (struct ev_loop)); |
852 | |
870 | |
853 | loop_init (EV_A_ methods); |
871 | loop_init (EV_A_ flags); |
854 | |
872 | |
855 | if (ev_method (EV_A)) |
873 | if (ev_method (EV_A)) |
856 | return loop; |
874 | return loop; |
857 | |
875 | |
858 | return 0; |
876 | return 0; |
… | |
… | |
876 | #if EV_MULTIPLICITY |
894 | #if EV_MULTIPLICITY |
877 | struct ev_loop * |
895 | struct ev_loop * |
878 | #else |
896 | #else |
879 | int |
897 | int |
880 | #endif |
898 | #endif |
881 | ev_default_loop (int methods) |
899 | ev_default_loop (unsigned int flags) |
882 | { |
900 | { |
883 | if (sigpipe [0] == sigpipe [1]) |
901 | if (sigpipe [0] == sigpipe [1]) |
884 | if (pipe (sigpipe)) |
902 | if (pipe (sigpipe)) |
885 | return 0; |
903 | return 0; |
886 | |
904 | |
… | |
… | |
890 | struct ev_loop *loop = default_loop = &default_loop_struct; |
908 | struct ev_loop *loop = default_loop = &default_loop_struct; |
891 | #else |
909 | #else |
892 | default_loop = 1; |
910 | default_loop = 1; |
893 | #endif |
911 | #endif |
894 | |
912 | |
895 | loop_init (EV_A_ methods); |
913 | loop_init (EV_A_ flags); |
896 | |
914 | |
897 | if (ev_method (EV_A)) |
915 | if (ev_method (EV_A)) |
898 | { |
916 | { |
899 | siginit (EV_A); |
917 | siginit (EV_A); |
900 | |
918 | |
901 | #ifndef WIN32 |
919 | #ifndef _WIN32 |
902 | ev_signal_init (&childev, childcb, SIGCHLD); |
920 | ev_signal_init (&childev, childcb, SIGCHLD); |
903 | ev_set_priority (&childev, EV_MAXPRI); |
921 | ev_set_priority (&childev, EV_MAXPRI); |
904 | ev_signal_start (EV_A_ &childev); |
922 | ev_signal_start (EV_A_ &childev); |
905 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
923 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
906 | #endif |
924 | #endif |
… | |
… | |
917 | { |
935 | { |
918 | #if EV_MULTIPLICITY |
936 | #if EV_MULTIPLICITY |
919 | struct ev_loop *loop = default_loop; |
937 | struct ev_loop *loop = default_loop; |
920 | #endif |
938 | #endif |
921 | |
939 | |
922 | #ifndef WIN32 |
940 | #ifndef _WIN32 |
923 | ev_ref (EV_A); /* child watcher */ |
941 | ev_ref (EV_A); /* child watcher */ |
924 | ev_signal_stop (EV_A_ &childev); |
942 | ev_signal_stop (EV_A_ &childev); |
925 | #endif |
943 | #endif |
926 | |
944 | |
927 | ev_ref (EV_A); /* signal watcher */ |
945 | ev_ref (EV_A); /* signal watcher */ |
… | |
… | |
987 | |
1005 | |
988 | /* first reschedule or stop timer */ |
1006 | /* first reschedule or stop timer */ |
989 | if (w->repeat) |
1007 | if (w->repeat) |
990 | { |
1008 | { |
991 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
1009 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
|
|
1010 | |
992 | ((WT)w)->at = mn_now + w->repeat; |
1011 | ((WT)w)->at += w->repeat; |
|
|
1012 | if (((WT)w)->at < mn_now) |
|
|
1013 | ((WT)w)->at = mn_now; |
|
|
1014 | |
993 | downheap ((WT *)timers, timercnt, 0); |
1015 | downheap ((WT *)timers, timercnt, 0); |
994 | } |
1016 | } |
995 | else |
1017 | else |
996 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1018 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
997 | |
1019 | |
998 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1020 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
999 | } |
1021 | } |
1000 | } |
1022 | } |
1001 | |
1023 | |
|
|
1024 | #if EV_PERIODICS |
1002 | static void |
1025 | static void |
1003 | periodics_reify (EV_P) |
1026 | periodics_reify (EV_P) |
1004 | { |
1027 | { |
1005 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1028 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1006 | { |
1029 | { |
… | |
… | |
1009 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1032 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1010 | |
1033 | |
1011 | /* first reschedule or stop timer */ |
1034 | /* first reschedule or stop timer */ |
1012 | if (w->reschedule_cb) |
1035 | if (w->reschedule_cb) |
1013 | { |
1036 | { |
1014 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1037 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1015 | |
|
|
1016 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1038 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1017 | downheap ((WT *)periodics, periodiccnt, 0); |
1039 | downheap ((WT *)periodics, periodiccnt, 0); |
1018 | } |
1040 | } |
1019 | else if (w->interval) |
1041 | else if (w->interval) |
1020 | { |
1042 | { |
… | |
… | |
1047 | |
1069 | |
1048 | /* now rebuild the heap */ |
1070 | /* now rebuild the heap */ |
1049 | for (i = periodiccnt >> 1; i--; ) |
1071 | for (i = periodiccnt >> 1; i--; ) |
1050 | downheap ((WT *)periodics, periodiccnt, i); |
1072 | downheap ((WT *)periodics, periodiccnt, i); |
1051 | } |
1073 | } |
|
|
1074 | #endif |
1052 | |
1075 | |
1053 | inline int |
1076 | inline int |
1054 | time_update_monotonic (EV_P) |
1077 | time_update_monotonic (EV_P) |
1055 | { |
1078 | { |
1056 | mn_now = get_clock (); |
1079 | mn_now = get_clock (); |
… | |
… | |
1090 | ev_rt_now = ev_time (); |
1113 | ev_rt_now = ev_time (); |
1091 | mn_now = get_clock (); |
1114 | mn_now = get_clock (); |
1092 | now_floor = mn_now; |
1115 | now_floor = mn_now; |
1093 | } |
1116 | } |
1094 | |
1117 | |
|
|
1118 | # if EV_PERIODICS |
1095 | periodics_reschedule (EV_A); |
1119 | periodics_reschedule (EV_A); |
|
|
1120 | # endif |
1096 | /* no timer adjustment, as the monotonic clock doesn't jump */ |
1121 | /* no timer adjustment, as the monotonic clock doesn't jump */ |
1097 | /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ |
1122 | /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ |
1098 | } |
1123 | } |
1099 | } |
1124 | } |
1100 | else |
1125 | else |
… | |
… | |
1102 | { |
1127 | { |
1103 | ev_rt_now = ev_time (); |
1128 | ev_rt_now = ev_time (); |
1104 | |
1129 | |
1105 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1130 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1106 | { |
1131 | { |
|
|
1132 | #if EV_PERIODICS |
1107 | periodics_reschedule (EV_A); |
1133 | periodics_reschedule (EV_A); |
|
|
1134 | #endif |
1108 | |
1135 | |
1109 | /* adjust timers. this is easy, as the offset is the same for all */ |
1136 | /* adjust timers. this is easy, as the offset is the same for all */ |
1110 | for (i = 0; i < timercnt; ++i) |
1137 | for (i = 0; i < timercnt; ++i) |
1111 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1138 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1112 | } |
1139 | } |
… | |
… | |
1133 | ev_loop (EV_P_ int flags) |
1160 | ev_loop (EV_P_ int flags) |
1134 | { |
1161 | { |
1135 | double block; |
1162 | double block; |
1136 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1163 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1137 | |
1164 | |
1138 | do |
1165 | while (activecnt) |
1139 | { |
1166 | { |
1140 | /* queue check watchers (and execute them) */ |
1167 | /* queue check watchers (and execute them) */ |
1141 | if (expect_false (preparecnt)) |
1168 | if (expect_false (preparecnt)) |
1142 | { |
1169 | { |
1143 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1170 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
… | |
… | |
1175 | { |
1202 | { |
1176 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
1203 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
1177 | if (block > to) block = to; |
1204 | if (block > to) block = to; |
1178 | } |
1205 | } |
1179 | |
1206 | |
|
|
1207 | #if EV_PERIODICS |
1180 | if (periodiccnt) |
1208 | if (periodiccnt) |
1181 | { |
1209 | { |
1182 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1210 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1183 | if (block > to) block = to; |
1211 | if (block > to) block = to; |
1184 | } |
1212 | } |
|
|
1213 | #endif |
1185 | |
1214 | |
1186 | if (block < 0.) block = 0.; |
1215 | if (block < 0.) block = 0.; |
1187 | } |
1216 | } |
1188 | |
1217 | |
1189 | method_poll (EV_A_ block); |
1218 | method_poll (EV_A_ block); |
… | |
… | |
1191 | /* update ev_rt_now, do magic */ |
1220 | /* update ev_rt_now, do magic */ |
1192 | time_update (EV_A); |
1221 | time_update (EV_A); |
1193 | |
1222 | |
1194 | /* queue pending timers and reschedule them */ |
1223 | /* queue pending timers and reschedule them */ |
1195 | timers_reify (EV_A); /* relative timers called last */ |
1224 | timers_reify (EV_A); /* relative timers called last */ |
|
|
1225 | #if EV_PERIODICS |
1196 | periodics_reify (EV_A); /* absolute timers called first */ |
1226 | periodics_reify (EV_A); /* absolute timers called first */ |
|
|
1227 | #endif |
1197 | |
1228 | |
1198 | /* queue idle watchers unless io or timers are pending */ |
1229 | /* queue idle watchers unless io or timers are pending */ |
1199 | if (idlecnt && !any_pending (EV_A)) |
1230 | if (idlecnt && !any_pending (EV_A)) |
1200 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1231 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1201 | |
1232 | |
1202 | /* queue check watchers, to be executed first */ |
1233 | /* queue check watchers, to be executed first */ |
1203 | if (checkcnt) |
1234 | if (checkcnt) |
1204 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1235 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1205 | |
1236 | |
1206 | call_pending (EV_A); |
1237 | call_pending (EV_A); |
|
|
1238 | |
|
|
1239 | if (loop_done) |
|
|
1240 | break; |
1207 | } |
1241 | } |
1208 | while (activecnt && !loop_done); |
|
|
1209 | |
1242 | |
1210 | if (loop_done != 2) |
1243 | if (loop_done != 2) |
1211 | loop_done = 0; |
1244 | loop_done = 0; |
1212 | } |
1245 | } |
1213 | |
1246 | |
… | |
… | |
1311 | ((WT)w)->at += mn_now; |
1344 | ((WT)w)->at += mn_now; |
1312 | |
1345 | |
1313 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1346 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1314 | |
1347 | |
1315 | ev_start (EV_A_ (W)w, ++timercnt); |
1348 | ev_start (EV_A_ (W)w, ++timercnt); |
1316 | array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); |
1349 | array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); |
1317 | timers [timercnt - 1] = w; |
1350 | timers [timercnt - 1] = w; |
1318 | upheap ((WT *)timers, timercnt - 1); |
1351 | upheap ((WT *)timers, timercnt - 1); |
1319 | |
1352 | |
1320 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1353 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1321 | } |
1354 | } |
… | |
… | |
1330 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1363 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1331 | |
1364 | |
1332 | if (((W)w)->active < timercnt--) |
1365 | if (((W)w)->active < timercnt--) |
1333 | { |
1366 | { |
1334 | timers [((W)w)->active - 1] = timers [timercnt]; |
1367 | timers [((W)w)->active - 1] = timers [timercnt]; |
1335 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1368 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1336 | } |
1369 | } |
1337 | |
1370 | |
1338 | ((WT)w)->at = w->repeat; |
1371 | ((WT)w)->at -= mn_now; |
1339 | |
1372 | |
1340 | ev_stop (EV_A_ (W)w); |
1373 | ev_stop (EV_A_ (W)w); |
1341 | } |
1374 | } |
1342 | |
1375 | |
1343 | void |
1376 | void |
1344 | ev_timer_again (EV_P_ struct ev_timer *w) |
1377 | ev_timer_again (EV_P_ struct ev_timer *w) |
1345 | { |
1378 | { |
1346 | if (ev_is_active (w)) |
1379 | if (ev_is_active (w)) |
1347 | { |
1380 | { |
1348 | if (w->repeat) |
1381 | if (w->repeat) |
|
|
1382 | { |
|
|
1383 | ((WT)w)->at = mn_now + w->repeat; |
1349 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); |
1384 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
|
|
1385 | } |
1350 | else |
1386 | else |
1351 | ev_timer_stop (EV_A_ w); |
1387 | ev_timer_stop (EV_A_ w); |
1352 | } |
1388 | } |
1353 | else if (w->repeat) |
1389 | else if (w->repeat) |
|
|
1390 | { |
|
|
1391 | w->at = w->repeat; |
1354 | ev_timer_start (EV_A_ w); |
1392 | ev_timer_start (EV_A_ w); |
|
|
1393 | } |
1355 | } |
1394 | } |
1356 | |
1395 | |
|
|
1396 | #if EV_PERIODICS |
1357 | void |
1397 | void |
1358 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1398 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1359 | { |
1399 | { |
1360 | if (ev_is_active (w)) |
1400 | if (ev_is_active (w)) |
1361 | return; |
1401 | return; |
… | |
… | |
1368 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1408 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1369 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1409 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1370 | } |
1410 | } |
1371 | |
1411 | |
1372 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1412 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1373 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1413 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1374 | periodics [periodiccnt - 1] = w; |
1414 | periodics [periodiccnt - 1] = w; |
1375 | upheap ((WT *)periodics, periodiccnt - 1); |
1415 | upheap ((WT *)periodics, periodiccnt - 1); |
1376 | |
1416 | |
1377 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1417 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1378 | } |
1418 | } |
… | |
… | |
1387 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1427 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1388 | |
1428 | |
1389 | if (((W)w)->active < periodiccnt--) |
1429 | if (((W)w)->active < periodiccnt--) |
1390 | { |
1430 | { |
1391 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1431 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1392 | downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1432 | adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1393 | } |
1433 | } |
1394 | |
1434 | |
1395 | ev_stop (EV_A_ (W)w); |
1435 | ev_stop (EV_A_ (W)w); |
1396 | } |
1436 | } |
1397 | |
1437 | |
… | |
… | |
1400 | { |
1440 | { |
1401 | /* TODO: use adjustheap and recalculation */ |
1441 | /* TODO: use adjustheap and recalculation */ |
1402 | ev_periodic_stop (EV_A_ w); |
1442 | ev_periodic_stop (EV_A_ w); |
1403 | ev_periodic_start (EV_A_ w); |
1443 | ev_periodic_start (EV_A_ w); |
1404 | } |
1444 | } |
|
|
1445 | #endif |
1405 | |
1446 | |
1406 | void |
1447 | void |
1407 | ev_idle_start (EV_P_ struct ev_idle *w) |
1448 | ev_idle_start (EV_P_ struct ev_idle *w) |
1408 | { |
1449 | { |
1409 | if (ev_is_active (w)) |
1450 | if (ev_is_active (w)) |
1410 | return; |
1451 | return; |
1411 | |
1452 | |
1412 | ev_start (EV_A_ (W)w, ++idlecnt); |
1453 | ev_start (EV_A_ (W)w, ++idlecnt); |
1413 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); |
1454 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1414 | idles [idlecnt - 1] = w; |
1455 | idles [idlecnt - 1] = w; |
1415 | } |
1456 | } |
1416 | |
1457 | |
1417 | void |
1458 | void |
1418 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1459 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1419 | { |
1460 | { |
1420 | ev_clear_pending (EV_A_ (W)w); |
1461 | ev_clear_pending (EV_A_ (W)w); |
1421 | if (ev_is_active (w)) |
1462 | if (!ev_is_active (w)) |
1422 | return; |
1463 | return; |
1423 | |
1464 | |
1424 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1465 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1425 | ev_stop (EV_A_ (W)w); |
1466 | ev_stop (EV_A_ (W)w); |
1426 | } |
1467 | } |
… | |
… | |
1430 | { |
1471 | { |
1431 | if (ev_is_active (w)) |
1472 | if (ev_is_active (w)) |
1432 | return; |
1473 | return; |
1433 | |
1474 | |
1434 | ev_start (EV_A_ (W)w, ++preparecnt); |
1475 | ev_start (EV_A_ (W)w, ++preparecnt); |
1435 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); |
1476 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1436 | prepares [preparecnt - 1] = w; |
1477 | prepares [preparecnt - 1] = w; |
1437 | } |
1478 | } |
1438 | |
1479 | |
1439 | void |
1480 | void |
1440 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1481 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1441 | { |
1482 | { |
1442 | ev_clear_pending (EV_A_ (W)w); |
1483 | ev_clear_pending (EV_A_ (W)w); |
1443 | if (ev_is_active (w)) |
1484 | if (!ev_is_active (w)) |
1444 | return; |
1485 | return; |
1445 | |
1486 | |
1446 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1487 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1447 | ev_stop (EV_A_ (W)w); |
1488 | ev_stop (EV_A_ (W)w); |
1448 | } |
1489 | } |
… | |
… | |
1452 | { |
1493 | { |
1453 | if (ev_is_active (w)) |
1494 | if (ev_is_active (w)) |
1454 | return; |
1495 | return; |
1455 | |
1496 | |
1456 | ev_start (EV_A_ (W)w, ++checkcnt); |
1497 | ev_start (EV_A_ (W)w, ++checkcnt); |
1457 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); |
1498 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1458 | checks [checkcnt - 1] = w; |
1499 | checks [checkcnt - 1] = w; |
1459 | } |
1500 | } |
1460 | |
1501 | |
1461 | void |
1502 | void |
1462 | ev_check_stop (EV_P_ struct ev_check *w) |
1503 | ev_check_stop (EV_P_ struct ev_check *w) |
1463 | { |
1504 | { |
1464 | ev_clear_pending (EV_A_ (W)w); |
1505 | ev_clear_pending (EV_A_ (W)w); |
1465 | if (ev_is_active (w)) |
1506 | if (!ev_is_active (w)) |
1466 | return; |
1507 | return; |
1467 | |
1508 | |
1468 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1509 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1469 | ev_stop (EV_A_ (W)w); |
1510 | ev_stop (EV_A_ (W)w); |
1470 | } |
1511 | } |
… | |
… | |
1488 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
1529 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
1489 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1530 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1490 | |
1531 | |
1491 | if (!((WL)w)->next) |
1532 | if (!((WL)w)->next) |
1492 | { |
1533 | { |
1493 | #if WIN32 |
1534 | #if _WIN32 |
1494 | signal (w->signum, sighandler); |
1535 | signal (w->signum, sighandler); |
1495 | #else |
1536 | #else |
1496 | struct sigaction sa; |
1537 | struct sigaction sa; |
1497 | sa.sa_handler = sighandler; |
1538 | sa.sa_handler = sighandler; |
1498 | sigfillset (&sa.sa_mask); |
1539 | sigfillset (&sa.sa_mask); |
… | |
… | |
1531 | |
1572 | |
1532 | void |
1573 | void |
1533 | ev_child_stop (EV_P_ struct ev_child *w) |
1574 | ev_child_stop (EV_P_ struct ev_child *w) |
1534 | { |
1575 | { |
1535 | ev_clear_pending (EV_A_ (W)w); |
1576 | ev_clear_pending (EV_A_ (W)w); |
1536 | if (ev_is_active (w)) |
1577 | if (!ev_is_active (w)) |
1537 | return; |
1578 | return; |
1538 | |
1579 | |
1539 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1580 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1540 | ev_stop (EV_A_ (W)w); |
1581 | ev_stop (EV_A_ (W)w); |
1541 | } |
1582 | } |