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

Comparing libev/ev.c (file contents):
Revision 1.57 by root, Sun Nov 4 16:43:53 2007 UTC vs.
Revision 1.64 by root, Sun Nov 4 23:14:11 2007 UTC

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_STANDALONE 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
276 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 306 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
277 events |= w->events; 307 events |= w->events;
278 308
279 anfd->reify = 0; 309 anfd->reify = 0;
280 310
281 if (anfd->events != events)
282 {
283 method_modify (EV_A_ fd, anfd->events, events); 311 method_modify (EV_A_ fd, anfd->events, events);
284 anfd->events = events; 312 anfd->events = events;
285 }
286 } 313 }
287 314
288 fdchangecnt = 0; 315 fdchangecnt = 0;
289} 316}
290 317
327 354
328/* called on ENOMEM in select/poll to kill some fds and retry */ 355/* called on ENOMEM in select/poll to kill some fds and retry */
329static void 356static void
330fd_enomem (EV_P) 357fd_enomem (EV_P)
331{ 358{
332 int fd = anfdmax; 359 int fd;
333 360
334 while (fd--) 361 for (fd = anfdmax; fd--; )
335 if (anfds [fd].events) 362 if (anfds [fd].events)
336 { 363 {
337 close (fd); 364 close (fd);
338 fd_kill (EV_A_ fd); 365 fd_kill (EV_A_ fd);
339 return; 366 return;
349 /* this should be highly optimised to not do anything but set a flag */ 376 /* this should be highly optimised to not do anything but set a flag */
350 for (fd = 0; fd < anfdmax; ++fd) 377 for (fd = 0; fd < anfdmax; ++fd)
351 if (anfds [fd].events) 378 if (anfds [fd].events)
352 { 379 {
353 anfds [fd].events = 0; 380 anfds [fd].events = 0;
354 fd_change (fd); 381 fd_change (EV_A_ fd);
355 } 382 }
356} 383}
357 384
358/*****************************************************************************/ 385/*****************************************************************************/
359 386
363 WT w = heap [k]; 390 WT w = heap [k];
364 391
365 while (k && heap [k >> 1]->at > w->at) 392 while (k && heap [k >> 1]->at > w->at)
366 { 393 {
367 heap [k] = heap [k >> 1]; 394 heap [k] = heap [k >> 1];
368 heap [k]->active = k + 1; 395 ((W)heap [k])->active = k + 1;
369 k >>= 1; 396 k >>= 1;
370 } 397 }
371 398
372 heap [k] = w; 399 heap [k] = w;
373 heap [k]->active = k + 1; 400 ((W)heap [k])->active = k + 1;
374 401
375} 402}
376 403
377static void 404static void
378downheap (WT *heap, int N, int k) 405downheap (WT *heap, int N, int k)
388 415
389 if (w->at <= heap [j]->at) 416 if (w->at <= heap [j]->at)
390 break; 417 break;
391 418
392 heap [k] = heap [j]; 419 heap [k] = heap [j];
393 heap [k]->active = k + 1; 420 ((W)heap [k])->active = k + 1;
394 k = j; 421 k = j;
395 } 422 }
396 423
397 heap [k] = w; 424 heap [k] = w;
398 heap [k]->active = k + 1; 425 ((W)heap [k])->active = k + 1;
399} 426}
400 427
401/*****************************************************************************/ 428/*****************************************************************************/
402 429
403typedef struct 430typedef struct
409static ANSIG *signals; 436static ANSIG *signals;
410static int signalmax; 437static int signalmax;
411 438
412static int sigpipe [2]; 439static int sigpipe [2];
413static sig_atomic_t volatile gotsig; 440static sig_atomic_t volatile gotsig;
441static struct ev_io sigev;
414 442
415static void 443static void
416signals_init (ANSIG *base, int count) 444signals_init (ANSIG *base, int count)
417{ 445{
418 while (count--) 446 while (count--)
476 504
477/*****************************************************************************/ 505/*****************************************************************************/
478 506
479#ifndef WIN32 507#ifndef WIN32
480 508
509static struct ev_child *childs [PID_HASHSIZE];
510static struct ev_signal childev;
511
481#ifndef WCONTINUED 512#ifndef WCONTINUED
482# define WCONTINUED 0 513# define WCONTINUED 0
483#endif 514#endif
484 515
485static void 516static void
488 struct ev_child *w; 519 struct ev_child *w;
489 520
490 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) 521 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
491 if (w->pid == pid || !w->pid) 522 if (w->pid == pid || !w->pid)
492 { 523 {
493 w->priority = sw->priority; /* need to do it *now* */ 524 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
494 w->rpid = pid; 525 w->rpid = pid;
495 w->rstatus = status; 526 w->rstatus = status;
496 event (EV_A_ (W)w, EV_CHILD); 527 event (EV_A_ (W)w, EV_CHILD);
497 } 528 }
498} 529}
499 530
500static void 531static void
520# include "ev_kqueue.c" 551# include "ev_kqueue.c"
521#endif 552#endif
522#if EV_USE_EPOLL 553#if EV_USE_EPOLL
523# include "ev_epoll.c" 554# include "ev_epoll.c"
524#endif 555#endif
525#if EV_USEV_POLL 556#if EV_USE_POLL
526# include "ev_poll.c" 557# include "ev_poll.c"
527#endif 558#endif
528#if EV_USE_SELECT 559#if EV_USE_SELECT
529# include "ev_select.c" 560# include "ev_select.c"
530#endif 561#endif
582 methods = atoi (getenv ("LIBEV_METHODS")); 613 methods = atoi (getenv ("LIBEV_METHODS"));
583 else 614 else
584 methods = EVMETHOD_ANY; 615 methods = EVMETHOD_ANY;
585 616
586 method = 0; 617 method = 0;
618#if EV_USE_WIN32
619 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
620#endif
587#if EV_USE_KQUEUE 621#if EV_USE_KQUEUE
588 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 622 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
589#endif 623#endif
590#if EV_USE_EPOLL 624#if EV_USE_EPOLL
591 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 625 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
592#endif 626#endif
593#if EV_USEV_POLL 627#if EV_USE_POLL
594 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 628 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
595#endif 629#endif
596#if EV_USE_SELECT 630#if EV_USE_SELECT
597 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 631 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
598#endif 632#endif
600} 634}
601 635
602void 636void
603loop_destroy (EV_P) 637loop_destroy (EV_P)
604{ 638{
639#if EV_USE_WIN32
640 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
641#endif
605#if EV_USE_KQUEUE 642#if EV_USE_KQUEUE
606 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 643 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
607#endif 644#endif
608#if EV_USE_EPOLL 645#if EV_USE_EPOLL
609 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 646 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
610#endif 647#endif
611#if EV_USEV_POLL 648#if EV_USE_POLL
612 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 649 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
613#endif 650#endif
614#if EV_USE_SELECT 651#if EV_USE_SELECT
615 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 652 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
616#endif 653#endif
637{ 674{
638 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); 675 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop));
639 676
640 loop_init (EV_A_ methods); 677 loop_init (EV_A_ methods);
641 678
642 if (ev_methods (EV_A)) 679 if (ev_method (EV_A))
643 return loop; 680 return loop;
644 681
645 return 0; 682 return 0;
646} 683}
647 684
724 761
725 loop_destroy (EV_A); 762 loop_destroy (EV_A);
726} 763}
727 764
728void 765void
729ev_default_fork (EV_P) 766ev_default_fork (void)
730{ 767{
768#if EV_MULTIPLICITY
769 struct ev_loop *loop = default_loop;
770#endif
771
731 loop_fork (EV_A); 772 loop_fork (EV_A);
732 773
733 ev_io_stop (EV_A_ &sigev); 774 ev_io_stop (EV_A_ &sigev);
734 close (sigpipe [0]); 775 close (sigpipe [0]);
735 close (sigpipe [1]); 776 close (sigpipe [1]);
752 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 793 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
753 794
754 if (p->w) 795 if (p->w)
755 { 796 {
756 p->w->pending = 0; 797 p->w->pending = 0;
798
757 p->w->cb (EV_A_ p->w, p->events); 799 (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events);
758 } 800 }
759 } 801 }
760} 802}
761 803
762static void 804static void
763timers_reify (EV_P) 805timers_reify (EV_P)
764{ 806{
765 while (timercnt && timers [0]->at <= mn_now) 807 while (timercnt && ((WT)timers [0])->at <= mn_now)
766 { 808 {
767 struct ev_timer *w = timers [0]; 809 struct ev_timer *w = timers [0];
810
811 assert (("inactive timer on timer heap detected", ev_is_active (w)));
768 812
769 /* first reschedule or stop timer */ 813 /* first reschedule or stop timer */
770 if (w->repeat) 814 if (w->repeat)
771 { 815 {
772 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 816 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
773 w->at = mn_now + w->repeat; 817 ((WT)w)->at = mn_now + w->repeat;
774 downheap ((WT *)timers, timercnt, 0); 818 downheap ((WT *)timers, timercnt, 0);
775 } 819 }
776 else 820 else
777 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 821 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
778 822
781} 825}
782 826
783static void 827static void
784periodics_reify (EV_P) 828periodics_reify (EV_P)
785{ 829{
786 while (periodiccnt && periodics [0]->at <= rt_now) 830 while (periodiccnt && ((WT)periodics [0])->at <= rt_now)
787 { 831 {
788 struct ev_periodic *w = periodics [0]; 832 struct ev_periodic *w = periodics [0];
833
834 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
789 835
790 /* first reschedule or stop timer */ 836 /* first reschedule or stop timer */
791 if (w->interval) 837 if (w->interval)
792 { 838 {
793 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; 839 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
794 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); 840 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
795 downheap ((WT *)periodics, periodiccnt, 0); 841 downheap ((WT *)periodics, periodiccnt, 0);
796 } 842 }
797 else 843 else
798 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 844 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
799 845
811 { 857 {
812 struct ev_periodic *w = periodics [i]; 858 struct ev_periodic *w = periodics [i];
813 859
814 if (w->interval) 860 if (w->interval)
815 { 861 {
816 ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; 862 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
817 863
818 if (fabs (diff) >= 1e-4) 864 if (fabs (diff) >= 1e-4)
819 { 865 {
820 ev_periodic_stop (EV_A_ w); 866 ev_periodic_stop (EV_A_ w);
821 ev_periodic_start (EV_A_ w); 867 ev_periodic_start (EV_A_ w);
882 { 928 {
883 periodics_reschedule (EV_A); 929 periodics_reschedule (EV_A);
884 930
885 /* adjust timers. this is easy, as the offset is the same for all */ 931 /* adjust timers. this is easy, as the offset is the same for all */
886 for (i = 0; i < timercnt; ++i) 932 for (i = 0; i < timercnt; ++i)
887 timers [i]->at += rt_now - mn_now; 933 ((WT)timers [i])->at += rt_now - mn_now;
888 } 934 }
889 935
890 mn_now = rt_now; 936 mn_now = rt_now;
891 } 937 }
892} 938}
943 { 989 {
944 block = MAX_BLOCKTIME; 990 block = MAX_BLOCKTIME;
945 991
946 if (timercnt) 992 if (timercnt)
947 { 993 {
948 ev_tstamp to = timers [0]->at - mn_now + method_fudge; 994 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
949 if (block > to) block = to; 995 if (block > to) block = to;
950 } 996 }
951 997
952 if (periodiccnt) 998 if (periodiccnt)
953 { 999 {
954 ev_tstamp to = periodics [0]->at - rt_now + method_fudge; 1000 ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge;
955 if (block > to) block = to; 1001 if (block > to) block = to;
956 } 1002 }
957 1003
958 if (block < 0.) block = 0.; 1004 if (block < 0.) block = 0.;
959 } 1005 }
1076ev_timer_start (EV_P_ struct ev_timer *w) 1122ev_timer_start (EV_P_ struct ev_timer *w)
1077{ 1123{
1078 if (ev_is_active (w)) 1124 if (ev_is_active (w))
1079 return; 1125 return;
1080 1126
1081 w->at += mn_now; 1127 ((WT)w)->at += mn_now;
1082 1128
1083 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1129 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1084 1130
1085 ev_start (EV_A_ (W)w, ++timercnt); 1131 ev_start (EV_A_ (W)w, ++timercnt);
1086 array_needsize (timers, timermax, timercnt, ); 1132 array_needsize (timers, timermax, timercnt, );
1087 timers [timercnt - 1] = w; 1133 timers [timercnt - 1] = w;
1088 upheap ((WT *)timers, timercnt - 1); 1134 upheap ((WT *)timers, timercnt - 1);
1135
1136 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1089} 1137}
1090 1138
1091void 1139void
1092ev_timer_stop (EV_P_ struct ev_timer *w) 1140ev_timer_stop (EV_P_ struct ev_timer *w)
1093{ 1141{
1094 ev_clear_pending (EV_A_ (W)w); 1142 ev_clear_pending (EV_A_ (W)w);
1095 if (!ev_is_active (w)) 1143 if (!ev_is_active (w))
1096 return; 1144 return;
1097 1145
1146 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1147
1098 if (w->active < timercnt--) 1148 if (((W)w)->active < timercnt--)
1099 { 1149 {
1100 timers [w->active - 1] = timers [timercnt]; 1150 timers [((W)w)->active - 1] = timers [timercnt];
1101 downheap ((WT *)timers, timercnt, w->active - 1); 1151 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1102 } 1152 }
1103 1153
1104 w->at = w->repeat; 1154 ((WT)w)->at = w->repeat;
1105 1155
1106 ev_stop (EV_A_ (W)w); 1156 ev_stop (EV_A_ (W)w);
1107} 1157}
1108 1158
1109void 1159void
1111{ 1161{
1112 if (ev_is_active (w)) 1162 if (ev_is_active (w))
1113 { 1163 {
1114 if (w->repeat) 1164 if (w->repeat)
1115 { 1165 {
1116 w->at = mn_now + w->repeat; 1166 ((WT)w)->at = mn_now + w->repeat;
1117 downheap ((WT *)timers, timercnt, w->active - 1); 1167 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1118 } 1168 }
1119 else 1169 else
1120 ev_timer_stop (EV_A_ w); 1170 ev_timer_stop (EV_A_ w);
1121 } 1171 }
1122 else if (w->repeat) 1172 else if (w->repeat)
1131 1181
1132 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1182 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1133 1183
1134 /* this formula differs from the one in periodic_reify because we do not always round up */ 1184 /* this formula differs from the one in periodic_reify because we do not always round up */
1135 if (w->interval) 1185 if (w->interval)
1136 w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; 1186 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1137 1187
1138 ev_start (EV_A_ (W)w, ++periodiccnt); 1188 ev_start (EV_A_ (W)w, ++periodiccnt);
1139 array_needsize (periodics, periodicmax, periodiccnt, ); 1189 array_needsize (periodics, periodicmax, periodiccnt, );
1140 periodics [periodiccnt - 1] = w; 1190 periodics [periodiccnt - 1] = w;
1141 upheap ((WT *)periodics, periodiccnt - 1); 1191 upheap ((WT *)periodics, periodiccnt - 1);
1192
1193 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1142} 1194}
1143 1195
1144void 1196void
1145ev_periodic_stop (EV_P_ struct ev_periodic *w) 1197ev_periodic_stop (EV_P_ struct ev_periodic *w)
1146{ 1198{
1147 ev_clear_pending (EV_A_ (W)w); 1199 ev_clear_pending (EV_A_ (W)w);
1148 if (!ev_is_active (w)) 1200 if (!ev_is_active (w))
1149 return; 1201 return;
1150 1202
1203 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1204
1151 if (w->active < periodiccnt--) 1205 if (((W)w)->active < periodiccnt--)
1152 { 1206 {
1153 periodics [w->active - 1] = periodics [periodiccnt]; 1207 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1154 downheap ((WT *)periodics, periodiccnt, w->active - 1); 1208 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1155 } 1209 }
1156 1210
1157 ev_stop (EV_A_ (W)w); 1211 ev_stop (EV_A_ (W)w);
1158} 1212}
1159 1213
1173{ 1227{
1174 ev_clear_pending (EV_A_ (W)w); 1228 ev_clear_pending (EV_A_ (W)w);
1175 if (ev_is_active (w)) 1229 if (ev_is_active (w))
1176 return; 1230 return;
1177 1231
1178 idles [w->active - 1] = idles [--idlecnt]; 1232 idles [((W)w)->active - 1] = idles [--idlecnt];
1179 ev_stop (EV_A_ (W)w); 1233 ev_stop (EV_A_ (W)w);
1180} 1234}
1181 1235
1182void 1236void
1183ev_prepare_start (EV_P_ struct ev_prepare *w) 1237ev_prepare_start (EV_P_ struct ev_prepare *w)
1195{ 1249{
1196 ev_clear_pending (EV_A_ (W)w); 1250 ev_clear_pending (EV_A_ (W)w);
1197 if (ev_is_active (w)) 1251 if (ev_is_active (w))
1198 return; 1252 return;
1199 1253
1200 prepares [w->active - 1] = prepares [--preparecnt]; 1254 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1201 ev_stop (EV_A_ (W)w); 1255 ev_stop (EV_A_ (W)w);
1202} 1256}
1203 1257
1204void 1258void
1205ev_check_start (EV_P_ struct ev_check *w) 1259ev_check_start (EV_P_ struct ev_check *w)
1217{ 1271{
1218 ev_clear_pending (EV_A_ (W)w); 1272 ev_clear_pending (EV_A_ (W)w);
1219 if (ev_is_active (w)) 1273 if (ev_is_active (w))
1220 return; 1274 return;
1221 1275
1222 checks [w->active - 1] = checks [--checkcnt]; 1276 checks [((W)w)->active - 1] = checks [--checkcnt];
1223 ev_stop (EV_A_ (W)w); 1277 ev_stop (EV_A_ (W)w);
1224} 1278}
1225 1279
1226#ifndef SA_RESTART 1280#ifndef SA_RESTART
1227# define SA_RESTART 0 1281# define SA_RESTART 0
1240 1294
1241 ev_start (EV_A_ (W)w, 1); 1295 ev_start (EV_A_ (W)w, 1);
1242 array_needsize (signals, signalmax, w->signum, signals_init); 1296 array_needsize (signals, signalmax, w->signum, signals_init);
1243 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1297 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1244 1298
1245 if (!w->next) 1299 if (!((WL)w)->next)
1246 { 1300 {
1247 struct sigaction sa; 1301 struct sigaction sa;
1248 sa.sa_handler = sighandler; 1302 sa.sa_handler = sighandler;
1249 sigfillset (&sa.sa_mask); 1303 sigfillset (&sa.sa_mask);
1250 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1304 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines