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

Comparing libev/ev.c (file contents):
Revision 1.90 by root, Sun Nov 11 00:05:59 2007 UTC vs.
Revision 1.103 by root, Mon Nov 12 00:31:08 2007 UTC

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
96# define EV_USE_EPOLL 0 107# define EV_USE_EPOLL 0
97#endif 108#endif
98 109
99#ifndef EV_USE_KQUEUE 110#ifndef EV_USE_KQUEUE
100# define EV_USE_KQUEUE 0 111# define EV_USE_KQUEUE 0
101#endif
102
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#endif
112 113
113#ifndef EV_USE_REALTIME 114#ifndef EV_USE_REALTIME
114# define EV_USE_REALTIME 1 115# define EV_USE_REALTIME 1
115#endif 116#endif
122#endif 123#endif
123 124
124#ifndef CLOCK_REALTIME 125#ifndef CLOCK_REALTIME
125# undef EV_USE_REALTIME 126# undef EV_USE_REALTIME
126# define EV_USE_REALTIME 0 127# define EV_USE_REALTIME 0
128#endif
129
130#if EV_SELECT_IS_WINSOCKET
131# include <winsock.h>
127#endif 132#endif
128 133
129/**/ 134/**/
130 135
131#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 136#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
151#define expect_true(expr) expect ((expr) != 0, 1) 156#define expect_true(expr) expect ((expr) != 0, 1)
152 157
153#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 158#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
154#define ABSPRI(w) ((w)->priority - EV_MINPRI) 159#define ABSPRI(w) ((w)->priority - EV_MINPRI)
155 160
161#define EMPTY /* required for microsofts broken pseudo-c compiler */
162
156typedef struct ev_watcher *W; 163typedef struct ev_watcher *W;
157typedef struct ev_watcher_list *WL; 164typedef struct ev_watcher_list *WL;
158typedef struct ev_watcher_time *WT; 165typedef struct ev_watcher_time *WT;
159 166
160static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 167static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
161 168
169#ifdef _WIN32
162#include "ev_win32.c" 170# include "ev_win32.c"
171#endif
163 172
164/*****************************************************************************/ 173/*****************************************************************************/
165 174
166static void (*syserr_cb)(const char *msg); 175static void (*syserr_cb)(const char *msg);
167 176
214typedef struct 223typedef struct
215{ 224{
216 WL head; 225 WL head;
217 unsigned char events; 226 unsigned char events;
218 unsigned char reify; 227 unsigned char reify;
228#if EV_SELECT_IS_WINSOCKET
229 SOCKET handle;
230#endif
219} ANFD; 231} ANFD;
220 232
221typedef struct 233typedef struct
222{ 234{
223 W w; 235 W w;
227#if EV_MULTIPLICITY 239#if EV_MULTIPLICITY
228 240
229 struct ev_loop 241 struct ev_loop
230 { 242 {
231 ev_tstamp ev_rt_now; 243 ev_tstamp ev_rt_now;
244 #define ev_rt_now ((loop)->ev_rt_now)
232 #define VAR(name,decl) decl; 245 #define VAR(name,decl) decl;
233 #include "ev_vars.h" 246 #include "ev_vars.h"
234 #undef VAR 247 #undef VAR
235 }; 248 };
236 #include "ev_wrap.h" 249 #include "ev_wrap.h"
249 262
250#endif 263#endif
251 264
252/*****************************************************************************/ 265/*****************************************************************************/
253 266
254inline ev_tstamp 267ev_tstamp
255ev_time (void) 268ev_time (void)
256{ 269{
257#if EV_USE_REALTIME 270#if EV_USE_REALTIME
258 struct timespec ts; 271 struct timespec ts;
259 clock_gettime (CLOCK_REALTIME, &ts); 272 clock_gettime (CLOCK_REALTIME, &ts);
311 stem ## max = array_roundsize (stem ## cnt >> 1); \ 324 stem ## max = array_roundsize (stem ## cnt >> 1); \
312 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 325 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
313 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 326 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
314 } 327 }
315 328
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) \ 329#define array_free(stem, idx) \
322 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 330 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
323 331
324/*****************************************************************************/ 332/*****************************************************************************/
325 333
399 int events = 0; 407 int events = 0;
400 408
401 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 409 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
402 events |= w->events; 410 events |= w->events;
403 411
412#if EV_SELECT_IS_WINSOCKET
413 if (events)
414 {
415 unsigned long argp;
416 anfd->handle = _get_osfhandle (fd);
417 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
418 }
419#endif
420
404 anfd->reify = 0; 421 anfd->reify = 0;
405 422
406 method_modify (EV_A_ fd, anfd->events, events); 423 method_modify (EV_A_ fd, anfd->events, events);
407 anfd->events = events; 424 anfd->events = events;
408 } 425 }
436} 453}
437 454
438static int 455static int
439fd_valid (int fd) 456fd_valid (int fd)
440{ 457{
441#ifdef WIN32 458#ifdef _WIN32
442 return !!win32_get_osfhandle (fd); 459 return _get_osfhandle (fd) != -1;
443#else 460#else
444 return fcntl (fd, F_GETFD) != -1; 461 return fcntl (fd, F_GETFD) != -1;
445#endif 462#endif
446} 463}
447 464
528 heap [k] = w; 545 heap [k] = w;
529 ((W)heap [k])->active = k + 1; 546 ((W)heap [k])->active = k + 1;
530} 547}
531 548
532inline void 549inline void
533adjustheap (WT *heap, int N, int k, ev_tstamp at) 550adjustheap (WT *heap, int N, int k)
534{ 551{
535 ev_tstamp old_at = heap [k]->at; 552 upheap (heap, k);
536 heap [k]->at = at;
537
538 if (old_at < at)
539 downheap (heap, N, k); 553 downheap (heap, N, k);
540 else
541 upheap (heap, k);
542} 554}
543 555
544/*****************************************************************************/ 556/*****************************************************************************/
545 557
546typedef struct 558typedef struct
569} 581}
570 582
571static void 583static void
572sighandler (int signum) 584sighandler (int signum)
573{ 585{
574#if WIN32 586#if _WIN32
575 signal (signum, sighandler); 587 signal (signum, sighandler);
576#endif 588#endif
577 589
578 signals [signum - 1].gotsig = 1; 590 signals [signum - 1].gotsig = 1;
579 591
580 if (!gotsig) 592 if (!gotsig)
581 { 593 {
582 int old_errno = errno; 594 int old_errno = errno;
583 gotsig = 1; 595 gotsig = 1;
584#ifdef WIN32
585 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
586#else
587 write (sigpipe [1], &signum, 1); 596 write (sigpipe [1], &signum, 1);
588#endif
589 errno = old_errno; 597 errno = old_errno;
590 } 598 }
591} 599}
592 600
593void 601void
613static void 621static void
614sigcb (EV_P_ struct ev_io *iow, int revents) 622sigcb (EV_P_ struct ev_io *iow, int revents)
615{ 623{
616 int signum; 624 int signum;
617 625
618#ifdef WIN32
619 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
620#else
621 read (sigpipe [0], &revents, 1); 626 read (sigpipe [0], &revents, 1);
622#endif
623 gotsig = 0; 627 gotsig = 0;
624 628
625 for (signum = signalmax; signum--; ) 629 for (signum = signalmax; signum--; )
626 if (signals [signum].gotsig) 630 if (signals [signum].gotsig)
627 ev_feed_signal_event (EV_A_ signum + 1); 631 ev_feed_signal_event (EV_A_ signum + 1);
628} 632}
629 633
634inline void
635fd_intern (int fd)
636{
637#ifdef _WIN32
638 int arg = 1;
639 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
640#else
641 fcntl (fd, F_SETFD, FD_CLOEXEC);
642 fcntl (fd, F_SETFL, O_NONBLOCK);
643#endif
644}
645
630static void 646static void
631siginit (EV_P) 647siginit (EV_P)
632{ 648{
633#ifndef WIN32 649 fd_intern (sigpipe [0]);
634 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); 650 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 651
642 ev_io_set (&sigev, sigpipe [0], EV_READ); 652 ev_io_set (&sigev, sigpipe [0], EV_READ);
643 ev_io_start (EV_A_ &sigev); 653 ev_io_start (EV_A_ &sigev);
644 ev_unref (EV_A); /* child watcher should not keep loop alive */ 654 ev_unref (EV_A); /* child watcher should not keep loop alive */
645} 655}
646 656
647/*****************************************************************************/ 657/*****************************************************************************/
648 658
649static struct ev_child *childs [PID_HASHSIZE]; 659static struct ev_child *childs [PID_HASHSIZE];
650 660
651#ifndef WIN32 661#ifndef _WIN32
652 662
653static struct ev_signal childev; 663static struct ev_signal childev;
654 664
655#ifndef WCONTINUED 665#ifndef WCONTINUED
656# define WCONTINUED 0 666# define WCONTINUED 0
717 727
718/* return true if we are running with elevated privileges and should ignore env variables */ 728/* return true if we are running with elevated privileges and should ignore env variables */
719static int 729static int
720enable_secure (void) 730enable_secure (void)
721{ 731{
722#ifdef WIN32 732#ifdef _WIN32
723 return 0; 733 return 0;
724#else 734#else
725 return getuid () != geteuid () 735 return getuid () != geteuid ()
726 || getgid () != getegid (); 736 || getgid () != getegid ();
727#endif 737#endif
756 methods = atoi (getenv ("LIBEV_METHODS")); 766 methods = atoi (getenv ("LIBEV_METHODS"));
757 else 767 else
758 methods = EVMETHOD_ANY; 768 methods = EVMETHOD_ANY;
759 769
760 method = 0; 770 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 771#if EV_USE_KQUEUE
765 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 772 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
766#endif 773#endif
767#if EV_USE_EPOLL 774#if EV_USE_EPOLL
768 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 775 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
782void 789void
783loop_destroy (EV_P) 790loop_destroy (EV_P)
784{ 791{
785 int i; 792 int i;
786 793
787#if EV_USE_WIN32
788 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
789#endif
790#if EV_USE_KQUEUE 794#if EV_USE_KQUEUE
791 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 795 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
792#endif 796#endif
793#if EV_USE_EPOLL 797#if EV_USE_EPOLL
794 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 798 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
802 806
803 for (i = NUMPRI; i--; ) 807 for (i = NUMPRI; i--; )
804 array_free (pending, [i]); 808 array_free (pending, [i]);
805 809
806 /* have to use the microsoft-never-gets-it-right macro */ 810 /* have to use the microsoft-never-gets-it-right macro */
807 array_free_microshit (fdchange); 811 array_free (fdchange, EMPTY);
808 array_free_microshit (timer); 812 array_free (timer, EMPTY);
809 array_free_microshit (periodic); 813#if EV_PERIODICS
810 array_free_microshit (idle); 814 array_free (periodic, EMPTY);
811 array_free_microshit (prepare); 815#endif
812 array_free_microshit (check); 816 array_free (idle, EMPTY);
817 array_free (prepare, EMPTY);
818 array_free (check, EMPTY);
813 819
814 method = 0; 820 method = 0;
815} 821}
816 822
817static void 823static void
896 902
897 if (ev_method (EV_A)) 903 if (ev_method (EV_A))
898 { 904 {
899 siginit (EV_A); 905 siginit (EV_A);
900 906
901#ifndef WIN32 907#ifndef _WIN32
902 ev_signal_init (&childev, childcb, SIGCHLD); 908 ev_signal_init (&childev, childcb, SIGCHLD);
903 ev_set_priority (&childev, EV_MAXPRI); 909 ev_set_priority (&childev, EV_MAXPRI);
904 ev_signal_start (EV_A_ &childev); 910 ev_signal_start (EV_A_ &childev);
905 ev_unref (EV_A); /* child watcher should not keep loop alive */ 911 ev_unref (EV_A); /* child watcher should not keep loop alive */
906#endif 912#endif
917{ 923{
918#if EV_MULTIPLICITY 924#if EV_MULTIPLICITY
919 struct ev_loop *loop = default_loop; 925 struct ev_loop *loop = default_loop;
920#endif 926#endif
921 927
922#ifndef WIN32 928#ifndef _WIN32
923 ev_ref (EV_A); /* child watcher */ 929 ev_ref (EV_A); /* child watcher */
924 ev_signal_stop (EV_A_ &childev); 930 ev_signal_stop (EV_A_ &childev);
925#endif 931#endif
926 932
927 ev_ref (EV_A); /* signal watcher */ 933 ev_ref (EV_A); /* signal watcher */
1001 1007
1002 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1008 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1003 } 1009 }
1004} 1010}
1005 1011
1012#if EV_PERIODICS
1006static void 1013static void
1007periodics_reify (EV_P) 1014periodics_reify (EV_P)
1008{ 1015{
1009 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1016 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1010 { 1017 {
1051 1058
1052 /* now rebuild the heap */ 1059 /* now rebuild the heap */
1053 for (i = periodiccnt >> 1; i--; ) 1060 for (i = periodiccnt >> 1; i--; )
1054 downheap ((WT *)periodics, periodiccnt, i); 1061 downheap ((WT *)periodics, periodiccnt, i);
1055} 1062}
1063#endif
1056 1064
1057inline int 1065inline int
1058time_update_monotonic (EV_P) 1066time_update_monotonic (EV_P)
1059{ 1067{
1060 mn_now = get_clock (); 1068 mn_now = get_clock ();
1094 ev_rt_now = ev_time (); 1102 ev_rt_now = ev_time ();
1095 mn_now = get_clock (); 1103 mn_now = get_clock ();
1096 now_floor = mn_now; 1104 now_floor = mn_now;
1097 } 1105 }
1098 1106
1107# if EV_PERIODICS
1099 periodics_reschedule (EV_A); 1108 periodics_reschedule (EV_A);
1109# endif
1100 /* no timer adjustment, as the monotonic clock doesn't jump */ 1110 /* no timer adjustment, as the monotonic clock doesn't jump */
1101 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ 1111 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1102 } 1112 }
1103 } 1113 }
1104 else 1114 else
1106 { 1116 {
1107 ev_rt_now = ev_time (); 1117 ev_rt_now = ev_time ();
1108 1118
1109 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1119 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
1110 { 1120 {
1121#if EV_PERIODICS
1111 periodics_reschedule (EV_A); 1122 periodics_reschedule (EV_A);
1123#endif
1112 1124
1113 /* adjust timers. this is easy, as the offset is the same for all */ 1125 /* adjust timers. this is easy, as the offset is the same for all */
1114 for (i = 0; i < timercnt; ++i) 1126 for (i = 0; i < timercnt; ++i)
1115 ((WT)timers [i])->at += ev_rt_now - mn_now; 1127 ((WT)timers [i])->at += ev_rt_now - mn_now;
1116 } 1128 }
1179 { 1191 {
1180 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1192 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
1181 if (block > to) block = to; 1193 if (block > to) block = to;
1182 } 1194 }
1183 1195
1196#if EV_PERIODICS
1184 if (periodiccnt) 1197 if (periodiccnt)
1185 { 1198 {
1186 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; 1199 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge;
1187 if (block > to) block = to; 1200 if (block > to) block = to;
1188 } 1201 }
1202#endif
1189 1203
1190 if (block < 0.) block = 0.; 1204 if (block < 0.) block = 0.;
1191 } 1205 }
1192 1206
1193 method_poll (EV_A_ block); 1207 method_poll (EV_A_ block);
1195 /* update ev_rt_now, do magic */ 1209 /* update ev_rt_now, do magic */
1196 time_update (EV_A); 1210 time_update (EV_A);
1197 1211
1198 /* queue pending timers and reschedule them */ 1212 /* queue pending timers and reschedule them */
1199 timers_reify (EV_A); /* relative timers called last */ 1213 timers_reify (EV_A); /* relative timers called last */
1214#if EV_PERIODICS
1200 periodics_reify (EV_A); /* absolute timers called first */ 1215 periodics_reify (EV_A); /* absolute timers called first */
1216#endif
1201 1217
1202 /* queue idle watchers unless io or timers are pending */ 1218 /* queue idle watchers unless io or timers are pending */
1203 if (idlecnt && !any_pending (EV_A)) 1219 if (idlecnt && !any_pending (EV_A))
1204 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1220 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1205 1221
1334 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1350 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1335 1351
1336 if (((W)w)->active < timercnt--) 1352 if (((W)w)->active < timercnt--)
1337 { 1353 {
1338 timers [((W)w)->active - 1] = timers [timercnt]; 1354 timers [((W)w)->active - 1] = timers [timercnt];
1339 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1355 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1340 } 1356 }
1341 1357
1342 ((WT)w)->at = w->repeat; 1358 ((WT)w)->at -= mn_now;
1343 1359
1344 ev_stop (EV_A_ (W)w); 1360 ev_stop (EV_A_ (W)w);
1345} 1361}
1346 1362
1347void 1363void
1348ev_timer_again (EV_P_ struct ev_timer *w) 1364ev_timer_again (EV_P_ struct ev_timer *w)
1349{ 1365{
1350 if (ev_is_active (w)) 1366 if (ev_is_active (w))
1351 { 1367 {
1352 if (w->repeat) 1368 if (w->repeat)
1369 {
1370 ((WT)w)->at = mn_now + w->repeat;
1353 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); 1371 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1372 }
1354 else 1373 else
1355 ev_timer_stop (EV_A_ w); 1374 ev_timer_stop (EV_A_ w);
1356 } 1375 }
1357 else if (w->repeat) 1376 else if (w->repeat)
1358 ev_timer_start (EV_A_ w); 1377 ev_timer_start (EV_A_ w);
1359} 1378}
1360 1379
1380#if EV_PERIODICS
1361void 1381void
1362ev_periodic_start (EV_P_ struct ev_periodic *w) 1382ev_periodic_start (EV_P_ struct ev_periodic *w)
1363{ 1383{
1364 if (ev_is_active (w)) 1384 if (ev_is_active (w))
1365 return; 1385 return;
1391 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1411 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1392 1412
1393 if (((W)w)->active < periodiccnt--) 1413 if (((W)w)->active < periodiccnt--)
1394 { 1414 {
1395 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1415 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1396 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1416 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1397 } 1417 }
1398 1418
1399 ev_stop (EV_A_ (W)w); 1419 ev_stop (EV_A_ (W)w);
1400} 1420}
1401 1421
1404{ 1424{
1405 /* TODO: use adjustheap and recalculation */ 1425 /* TODO: use adjustheap and recalculation */
1406 ev_periodic_stop (EV_A_ w); 1426 ev_periodic_stop (EV_A_ w);
1407 ev_periodic_start (EV_A_ w); 1427 ev_periodic_start (EV_A_ w);
1408} 1428}
1429#endif
1409 1430
1410void 1431void
1411ev_idle_start (EV_P_ struct ev_idle *w) 1432ev_idle_start (EV_P_ struct ev_idle *w)
1412{ 1433{
1413 if (ev_is_active (w)) 1434 if (ev_is_active (w))
1420 1441
1421void 1442void
1422ev_idle_stop (EV_P_ struct ev_idle *w) 1443ev_idle_stop (EV_P_ struct ev_idle *w)
1423{ 1444{
1424 ev_clear_pending (EV_A_ (W)w); 1445 ev_clear_pending (EV_A_ (W)w);
1425 if (ev_is_active (w)) 1446 if (!ev_is_active (w))
1426 return; 1447 return;
1427 1448
1428 idles [((W)w)->active - 1] = idles [--idlecnt]; 1449 idles [((W)w)->active - 1] = idles [--idlecnt];
1429 ev_stop (EV_A_ (W)w); 1450 ev_stop (EV_A_ (W)w);
1430} 1451}
1442 1463
1443void 1464void
1444ev_prepare_stop (EV_P_ struct ev_prepare *w) 1465ev_prepare_stop (EV_P_ struct ev_prepare *w)
1445{ 1466{
1446 ev_clear_pending (EV_A_ (W)w); 1467 ev_clear_pending (EV_A_ (W)w);
1447 if (ev_is_active (w)) 1468 if (!ev_is_active (w))
1448 return; 1469 return;
1449 1470
1450 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1471 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1451 ev_stop (EV_A_ (W)w); 1472 ev_stop (EV_A_ (W)w);
1452} 1473}
1464 1485
1465void 1486void
1466ev_check_stop (EV_P_ struct ev_check *w) 1487ev_check_stop (EV_P_ struct ev_check *w)
1467{ 1488{
1468 ev_clear_pending (EV_A_ (W)w); 1489 ev_clear_pending (EV_A_ (W)w);
1469 if (ev_is_active (w)) 1490 if (!ev_is_active (w))
1470 return; 1491 return;
1471 1492
1472 checks [((W)w)->active - 1] = checks [--checkcnt]; 1493 checks [((W)w)->active - 1] = checks [--checkcnt];
1473 ev_stop (EV_A_ (W)w); 1494 ev_stop (EV_A_ (W)w);
1474} 1495}
1492 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); 1513 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1493 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1514 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1494 1515
1495 if (!((WL)w)->next) 1516 if (!((WL)w)->next)
1496 { 1517 {
1497#if WIN32 1518#if _WIN32
1498 signal (w->signum, sighandler); 1519 signal (w->signum, sighandler);
1499#else 1520#else
1500 struct sigaction sa; 1521 struct sigaction sa;
1501 sa.sa_handler = sighandler; 1522 sa.sa_handler = sighandler;
1502 sigfillset (&sa.sa_mask); 1523 sigfillset (&sa.sa_mask);
1535 1556
1536void 1557void
1537ev_child_stop (EV_P_ struct ev_child *w) 1558ev_child_stop (EV_P_ struct ev_child *w)
1538{ 1559{
1539 ev_clear_pending (EV_A_ (W)w); 1560 ev_clear_pending (EV_A_ (W)w);
1540 if (ev_is_active (w)) 1561 if (!ev_is_active (w))
1541 return; 1562 return;
1542 1563
1543 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1564 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1544 ev_stop (EV_A_ (W)w); 1565 ev_stop (EV_A_ (W)w);
1545} 1566}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines