ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.58 by root, Sun Nov 4 16:52:52 2007 UTC vs.
Revision 1.66 by root, Sun Nov 4 23:30:53 2007 UTC

26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#ifndef EV_EMBED 31#ifndef EV_STANDALONE
32# include "config.h" 32# include "config.h"
33
34# if HAVE_CLOCK_GETTIME
35# define EV_USE_MONOTONIC 1
36# define EV_USE_REALTIME 1
37# endif
38
39# if HAVE_SELECT && HAVE_SYS_SELECT_H
40# define EV_USE_SELECT 1
41# endif
42
43# if HAVE_POLL && HAVE_POLL_H
44# define EV_USE_POLL 1
45# endif
46
47# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
48# define EV_USE_EPOLL 1
49# endif
50
51# if HAVE_KQUEUE && HAVE_WORKING_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
52# define EV_USE_KQUEUE 1
53# endif
54
33#endif 55#endif
34 56
35#include <math.h> 57#include <math.h>
36#include <stdlib.h> 58#include <stdlib.h>
37#include <unistd.h> 59#include <unistd.h>
58 80
59#ifndef EV_USE_SELECT 81#ifndef EV_USE_SELECT
60# define EV_USE_SELECT 1 82# define EV_USE_SELECT 1
61#endif 83#endif
62 84
63#ifndef EV_USEV_POLL 85#ifndef EV_USE_POLL
64# define EV_USEV_POLL 0 /* poll is usually slower than select, and not as well tested */ 86# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
65#endif 87#endif
66 88
67#ifndef EV_USE_EPOLL 89#ifndef EV_USE_EPOLL
68# define EV_USE_EPOLL 0 90# define EV_USE_EPOLL 0
69#endif 91#endif
70 92
71#ifndef EV_USE_KQUEUE 93#ifndef EV_USE_KQUEUE
72# define EV_USE_KQUEUE 0 94# define EV_USE_KQUEUE 0
95#endif
96
97#ifndef EV_USE_WIN32
98# ifdef WIN32
99# define EV_USE_WIN32 1
100# else
101# define EV_USE_WIN32 0
102# endif
73#endif 103#endif
74 104
75#ifndef EV_USE_REALTIME 105#ifndef EV_USE_REALTIME
76# define EV_USE_REALTIME 1 106# define EV_USE_REALTIME 1
77#endif 107#endif
93#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 123#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
94#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 124#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
95#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 125#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
96/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 126/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
97 127
98#ifndef EV_EMBED
99# include "ev.h" 128#include "ev.h"
100#endif
101 129
102#if __GNUC__ >= 3 130#if __GNUC__ >= 3
103# define expect(expr,value) __builtin_expect ((expr),(value)) 131# define expect(expr,value) __builtin_expect ((expr),(value))
104# define inline inline 132# define inline inline
105#else 133#else
204 base = realloc (base, sizeof (*base) * (newcnt)); \ 232 base = realloc (base, sizeof (*base) * (newcnt)); \
205 init (base + cur, newcnt - cur); \ 233 init (base + cur, newcnt - cur); \
206 cur = newcnt; \ 234 cur = newcnt; \
207 } 235 }
208 236
237#define array_free(stem, idx) \
238 free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
239
209/*****************************************************************************/ 240/*****************************************************************************/
210 241
211static void 242static void
212anfds_init (ANFD *base, int count) 243anfds_init (ANFD *base, int count)
213{ 244{
278 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 309 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
279 events |= w->events; 310 events |= w->events;
280 311
281 anfd->reify = 0; 312 anfd->reify = 0;
282 313
283 if (anfd->events != events)
284 {
285 method_modify (EV_A_ fd, anfd->events, events); 314 method_modify (EV_A_ fd, anfd->events, events);
286 anfd->events = events; 315 anfd->events = events;
287 }
288 } 316 }
289 317
290 fdchangecnt = 0; 318 fdchangecnt = 0;
291} 319}
292 320
329 357
330/* called on ENOMEM in select/poll to kill some fds and retry */ 358/* called on ENOMEM in select/poll to kill some fds and retry */
331static void 359static void
332fd_enomem (EV_P) 360fd_enomem (EV_P)
333{ 361{
334 int fd = anfdmax; 362 int fd;
335 363
336 while (fd--) 364 for (fd = anfdmax; fd--; )
337 if (anfds [fd].events) 365 if (anfds [fd].events)
338 { 366 {
339 close (fd); 367 close (fd);
340 fd_kill (EV_A_ fd); 368 fd_kill (EV_A_ fd);
341 return; 369 return;
351 /* this should be highly optimised to not do anything but set a flag */ 379 /* this should be highly optimised to not do anything but set a flag */
352 for (fd = 0; fd < anfdmax; ++fd) 380 for (fd = 0; fd < anfdmax; ++fd)
353 if (anfds [fd].events) 381 if (anfds [fd].events)
354 { 382 {
355 anfds [fd].events = 0; 383 anfds [fd].events = 0;
356 fd_change (fd); 384 fd_change (EV_A_ fd);
357 } 385 }
358} 386}
359 387
360/*****************************************************************************/ 388/*****************************************************************************/
361 389
365 WT w = heap [k]; 393 WT w = heap [k];
366 394
367 while (k && heap [k >> 1]->at > w->at) 395 while (k && heap [k >> 1]->at > w->at)
368 { 396 {
369 heap [k] = heap [k >> 1]; 397 heap [k] = heap [k >> 1];
370 heap [k]->active = k + 1; 398 ((W)heap [k])->active = k + 1;
371 k >>= 1; 399 k >>= 1;
372 } 400 }
373 401
374 heap [k] = w; 402 heap [k] = w;
375 heap [k]->active = k + 1; 403 ((W)heap [k])->active = k + 1;
376 404
377} 405}
378 406
379static void 407static void
380downheap (WT *heap, int N, int k) 408downheap (WT *heap, int N, int k)
390 418
391 if (w->at <= heap [j]->at) 419 if (w->at <= heap [j]->at)
392 break; 420 break;
393 421
394 heap [k] = heap [j]; 422 heap [k] = heap [j];
395 heap [k]->active = k + 1; 423 ((W)heap [k])->active = k + 1;
396 k = j; 424 k = j;
397 } 425 }
398 426
399 heap [k] = w; 427 heap [k] = w;
400 heap [k]->active = k + 1; 428 ((W)heap [k])->active = k + 1;
401} 429}
402 430
403/*****************************************************************************/ 431/*****************************************************************************/
404 432
405typedef struct 433typedef struct
411static ANSIG *signals; 439static ANSIG *signals;
412static int signalmax; 440static int signalmax;
413 441
414static int sigpipe [2]; 442static int sigpipe [2];
415static sig_atomic_t volatile gotsig; 443static sig_atomic_t volatile gotsig;
444static struct ev_io sigev;
416 445
417static void 446static void
418signals_init (ANSIG *base, int count) 447signals_init (ANSIG *base, int count)
419{ 448{
420 while (count--) 449 while (count--)
478 507
479/*****************************************************************************/ 508/*****************************************************************************/
480 509
481#ifndef WIN32 510#ifndef WIN32
482 511
512static struct ev_child *childs [PID_HASHSIZE];
513static struct ev_signal childev;
514
483#ifndef WCONTINUED 515#ifndef WCONTINUED
484# define WCONTINUED 0 516# define WCONTINUED 0
485#endif 517#endif
486 518
487static void 519static void
490 struct ev_child *w; 522 struct ev_child *w;
491 523
492 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) 524 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
493 if (w->pid == pid || !w->pid) 525 if (w->pid == pid || !w->pid)
494 { 526 {
495 w->priority = sw->priority; /* need to do it *now* */ 527 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
496 w->rpid = pid; 528 w->rpid = pid;
497 w->rstatus = status; 529 w->rstatus = status;
498 event (EV_A_ (W)w, EV_CHILD); 530 event (EV_A_ (W)w, EV_CHILD);
499 } 531 }
500} 532}
501 533
502static void 534static void
522# include "ev_kqueue.c" 554# include "ev_kqueue.c"
523#endif 555#endif
524#if EV_USE_EPOLL 556#if EV_USE_EPOLL
525# include "ev_epoll.c" 557# include "ev_epoll.c"
526#endif 558#endif
527#if EV_USEV_POLL 559#if EV_USE_POLL
528# include "ev_poll.c" 560# include "ev_poll.c"
529#endif 561#endif
530#if EV_USE_SELECT 562#if EV_USE_SELECT
531# include "ev_select.c" 563# include "ev_select.c"
532#endif 564#endif
584 methods = atoi (getenv ("LIBEV_METHODS")); 616 methods = atoi (getenv ("LIBEV_METHODS"));
585 else 617 else
586 methods = EVMETHOD_ANY; 618 methods = EVMETHOD_ANY;
587 619
588 method = 0; 620 method = 0;
621#if EV_USE_WIN32
622 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
623#endif
589#if EV_USE_KQUEUE 624#if EV_USE_KQUEUE
590 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 625 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
591#endif 626#endif
592#if EV_USE_EPOLL 627#if EV_USE_EPOLL
593 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 628 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
594#endif 629#endif
595#if EV_USEV_POLL 630#if EV_USE_POLL
596 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 631 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
597#endif 632#endif
598#if EV_USE_SELECT 633#if EV_USE_SELECT
599 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 634 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
600#endif 635#endif
602} 637}
603 638
604void 639void
605loop_destroy (EV_P) 640loop_destroy (EV_P)
606{ 641{
642 int i;
643
644#if EV_USE_WIN32
645 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
646#endif
607#if EV_USE_KQUEUE 647#if EV_USE_KQUEUE
608 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 648 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
609#endif 649#endif
610#if EV_USE_EPOLL 650#if EV_USE_EPOLL
611 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 651 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
612#endif 652#endif
613#if EV_USEV_POLL 653#if EV_USE_POLL
614 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 654 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
615#endif 655#endif
616#if EV_USE_SELECT 656#if EV_USE_SELECT
617 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 657 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
618#endif 658#endif
659
660 for (i = NUMPRI; i--; )
661 array_free (pending, [i]);
662
663 array_free (fdchange, );
664 array_free (timer, );
665 array_free (periodic, );
666 array_free (idle, );
667 array_free (prepare, );
668 array_free (check, );
619 669
620 method = 0; 670 method = 0;
621 /*TODO*/ 671 /*TODO*/
622} 672}
623 673
639{ 689{
640 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); 690 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop));
641 691
642 loop_init (EV_A_ methods); 692 loop_init (EV_A_ methods);
643 693
644 if (ev_methods (EV_A)) 694 if (ev_method (EV_A))
645 return loop; 695 return loop;
646 696
647 return 0; 697 return 0;
648} 698}
649 699
726 776
727 loop_destroy (EV_A); 777 loop_destroy (EV_A);
728} 778}
729 779
730void 780void
731ev_default_fork (EV_P) 781ev_default_fork (void)
732{ 782{
783#if EV_MULTIPLICITY
784 struct ev_loop *loop = default_loop;
785#endif
786
733 loop_fork (EV_A); 787 loop_fork (EV_A);
734 788
735 ev_io_stop (EV_A_ &sigev); 789 ev_io_stop (EV_A_ &sigev);
736 close (sigpipe [0]); 790 close (sigpipe [0]);
737 close (sigpipe [1]); 791 close (sigpipe [1]);
762} 816}
763 817
764static void 818static void
765timers_reify (EV_P) 819timers_reify (EV_P)
766{ 820{
767 while (timercnt && timers [0]->at <= mn_now) 821 while (timercnt && ((WT)timers [0])->at <= mn_now)
768 { 822 {
769 struct ev_timer *w = timers [0]; 823 struct ev_timer *w = timers [0];
824
825 assert (("inactive timer on timer heap detected", ev_is_active (w)));
770 826
771 /* first reschedule or stop timer */ 827 /* first reschedule or stop timer */
772 if (w->repeat) 828 if (w->repeat)
773 { 829 {
774 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 830 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
775 w->at = mn_now + w->repeat; 831 ((WT)w)->at = mn_now + w->repeat;
776 downheap ((WT *)timers, timercnt, 0); 832 downheap ((WT *)timers, timercnt, 0);
777 } 833 }
778 else 834 else
779 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 835 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
780 836
783} 839}
784 840
785static void 841static void
786periodics_reify (EV_P) 842periodics_reify (EV_P)
787{ 843{
788 while (periodiccnt && periodics [0]->at <= rt_now) 844 while (periodiccnt && ((WT)periodics [0])->at <= rt_now)
789 { 845 {
790 struct ev_periodic *w = periodics [0]; 846 struct ev_periodic *w = periodics [0];
847
848 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
791 849
792 /* first reschedule or stop timer */ 850 /* first reschedule or stop timer */
793 if (w->interval) 851 if (w->interval)
794 { 852 {
795 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; 853 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
796 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); 854 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
797 downheap ((WT *)periodics, periodiccnt, 0); 855 downheap ((WT *)periodics, periodiccnt, 0);
798 } 856 }
799 else 857 else
800 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 858 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
801 859
813 { 871 {
814 struct ev_periodic *w = periodics [i]; 872 struct ev_periodic *w = periodics [i];
815 873
816 if (w->interval) 874 if (w->interval)
817 { 875 {
818 ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; 876 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
819 877
820 if (fabs (diff) >= 1e-4) 878 if (fabs (diff) >= 1e-4)
821 { 879 {
822 ev_periodic_stop (EV_A_ w); 880 ev_periodic_stop (EV_A_ w);
823 ev_periodic_start (EV_A_ w); 881 ev_periodic_start (EV_A_ w);
884 { 942 {
885 periodics_reschedule (EV_A); 943 periodics_reschedule (EV_A);
886 944
887 /* adjust timers. this is easy, as the offset is the same for all */ 945 /* adjust timers. this is easy, as the offset is the same for all */
888 for (i = 0; i < timercnt; ++i) 946 for (i = 0; i < timercnt; ++i)
889 timers [i]->at += rt_now - mn_now; 947 ((WT)timers [i])->at += rt_now - mn_now;
890 } 948 }
891 949
892 mn_now = rt_now; 950 mn_now = rt_now;
893 } 951 }
894} 952}
945 { 1003 {
946 block = MAX_BLOCKTIME; 1004 block = MAX_BLOCKTIME;
947 1005
948 if (timercnt) 1006 if (timercnt)
949 { 1007 {
950 ev_tstamp to = timers [0]->at - mn_now + method_fudge; 1008 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
951 if (block > to) block = to; 1009 if (block > to) block = to;
952 } 1010 }
953 1011
954 if (periodiccnt) 1012 if (periodiccnt)
955 { 1013 {
956 ev_tstamp to = periodics [0]->at - rt_now + method_fudge; 1014 ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge;
957 if (block > to) block = to; 1015 if (block > to) block = to;
958 } 1016 }
959 1017
960 if (block < 0.) block = 0.; 1018 if (block < 0.) block = 0.;
961 } 1019 }
1078ev_timer_start (EV_P_ struct ev_timer *w) 1136ev_timer_start (EV_P_ struct ev_timer *w)
1079{ 1137{
1080 if (ev_is_active (w)) 1138 if (ev_is_active (w))
1081 return; 1139 return;
1082 1140
1083 w->at += mn_now; 1141 ((WT)w)->at += mn_now;
1084 1142
1085 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1143 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1086 1144
1087 ev_start (EV_A_ (W)w, ++timercnt); 1145 ev_start (EV_A_ (W)w, ++timercnt);
1088 array_needsize (timers, timermax, timercnt, ); 1146 array_needsize (timers, timermax, timercnt, );
1089 timers [timercnt - 1] = w; 1147 timers [timercnt - 1] = w;
1090 upheap ((WT *)timers, timercnt - 1); 1148 upheap ((WT *)timers, timercnt - 1);
1149
1150 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1091} 1151}
1092 1152
1093void 1153void
1094ev_timer_stop (EV_P_ struct ev_timer *w) 1154ev_timer_stop (EV_P_ struct ev_timer *w)
1095{ 1155{
1096 ev_clear_pending (EV_A_ (W)w); 1156 ev_clear_pending (EV_A_ (W)w);
1097 if (!ev_is_active (w)) 1157 if (!ev_is_active (w))
1098 return; 1158 return;
1099 1159
1160 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1161
1100 if (w->active < timercnt--) 1162 if (((W)w)->active < timercnt--)
1101 { 1163 {
1102 timers [w->active - 1] = timers [timercnt]; 1164 timers [((W)w)->active - 1] = timers [timercnt];
1103 downheap ((WT *)timers, timercnt, w->active - 1); 1165 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1104 } 1166 }
1105 1167
1106 w->at = w->repeat; 1168 ((WT)w)->at = w->repeat;
1107 1169
1108 ev_stop (EV_A_ (W)w); 1170 ev_stop (EV_A_ (W)w);
1109} 1171}
1110 1172
1111void 1173void
1113{ 1175{
1114 if (ev_is_active (w)) 1176 if (ev_is_active (w))
1115 { 1177 {
1116 if (w->repeat) 1178 if (w->repeat)
1117 { 1179 {
1118 w->at = mn_now + w->repeat; 1180 ((WT)w)->at = mn_now + w->repeat;
1119 downheap ((WT *)timers, timercnt, w->active - 1); 1181 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1120 } 1182 }
1121 else 1183 else
1122 ev_timer_stop (EV_A_ w); 1184 ev_timer_stop (EV_A_ w);
1123 } 1185 }
1124 else if (w->repeat) 1186 else if (w->repeat)
1133 1195
1134 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1196 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1135 1197
1136 /* this formula differs from the one in periodic_reify because we do not always round up */ 1198 /* this formula differs from the one in periodic_reify because we do not always round up */
1137 if (w->interval) 1199 if (w->interval)
1138 w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; 1200 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1139 1201
1140 ev_start (EV_A_ (W)w, ++periodiccnt); 1202 ev_start (EV_A_ (W)w, ++periodiccnt);
1141 array_needsize (periodics, periodicmax, periodiccnt, ); 1203 array_needsize (periodics, periodicmax, periodiccnt, );
1142 periodics [periodiccnt - 1] = w; 1204 periodics [periodiccnt - 1] = w;
1143 upheap ((WT *)periodics, periodiccnt - 1); 1205 upheap ((WT *)periodics, periodiccnt - 1);
1206
1207 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1144} 1208}
1145 1209
1146void 1210void
1147ev_periodic_stop (EV_P_ struct ev_periodic *w) 1211ev_periodic_stop (EV_P_ struct ev_periodic *w)
1148{ 1212{
1149 ev_clear_pending (EV_A_ (W)w); 1213 ev_clear_pending (EV_A_ (W)w);
1150 if (!ev_is_active (w)) 1214 if (!ev_is_active (w))
1151 return; 1215 return;
1152 1216
1217 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1218
1153 if (w->active < periodiccnt--) 1219 if (((W)w)->active < periodiccnt--)
1154 { 1220 {
1155 periodics [w->active - 1] = periodics [periodiccnt]; 1221 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1156 downheap ((WT *)periodics, periodiccnt, w->active - 1); 1222 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1157 } 1223 }
1158 1224
1159 ev_stop (EV_A_ (W)w); 1225 ev_stop (EV_A_ (W)w);
1160} 1226}
1161 1227
1175{ 1241{
1176 ev_clear_pending (EV_A_ (W)w); 1242 ev_clear_pending (EV_A_ (W)w);
1177 if (ev_is_active (w)) 1243 if (ev_is_active (w))
1178 return; 1244 return;
1179 1245
1180 idles [w->active - 1] = idles [--idlecnt]; 1246 idles [((W)w)->active - 1] = idles [--idlecnt];
1181 ev_stop (EV_A_ (W)w); 1247 ev_stop (EV_A_ (W)w);
1182} 1248}
1183 1249
1184void 1250void
1185ev_prepare_start (EV_P_ struct ev_prepare *w) 1251ev_prepare_start (EV_P_ struct ev_prepare *w)
1197{ 1263{
1198 ev_clear_pending (EV_A_ (W)w); 1264 ev_clear_pending (EV_A_ (W)w);
1199 if (ev_is_active (w)) 1265 if (ev_is_active (w))
1200 return; 1266 return;
1201 1267
1202 prepares [w->active - 1] = prepares [--preparecnt]; 1268 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1203 ev_stop (EV_A_ (W)w); 1269 ev_stop (EV_A_ (W)w);
1204} 1270}
1205 1271
1206void 1272void
1207ev_check_start (EV_P_ struct ev_check *w) 1273ev_check_start (EV_P_ struct ev_check *w)
1219{ 1285{
1220 ev_clear_pending (EV_A_ (W)w); 1286 ev_clear_pending (EV_A_ (W)w);
1221 if (ev_is_active (w)) 1287 if (ev_is_active (w))
1222 return; 1288 return;
1223 1289
1224 checks [w->active - 1] = checks [--checkcnt]; 1290 checks [((W)w)->active - 1] = checks [--checkcnt];
1225 ev_stop (EV_A_ (W)w); 1291 ev_stop (EV_A_ (W)w);
1226} 1292}
1227 1293
1228#ifndef SA_RESTART 1294#ifndef SA_RESTART
1229# define SA_RESTART 0 1295# define SA_RESTART 0
1242 1308
1243 ev_start (EV_A_ (W)w, 1); 1309 ev_start (EV_A_ (W)w, 1);
1244 array_needsize (signals, signalmax, w->signum, signals_init); 1310 array_needsize (signals, signalmax, w->signum, signals_init);
1245 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1311 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1246 1312
1247 if (!w->next) 1313 if (!((WL)w)->next)
1248 { 1314 {
1249 struct sigaction sa; 1315 struct sigaction sa;
1250 sa.sa_handler = sighandler; 1316 sa.sa_handler = sighandler;
1251 sigfillset (&sa.sa_mask); 1317 sigfillset (&sa.sa_mask);
1252 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1318 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines