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

Comparing libev/ev.c (file contents):
Revision 1.71 by root, Tue Nov 6 13:17:55 2007 UTC vs.
Revision 1.83 by root, Fri Nov 9 21:48:23 2007 UTC

64#include <assert.h> 64#include <assert.h>
65#include <errno.h> 65#include <errno.h>
66#include <sys/types.h> 66#include <sys/types.h>
67#include <time.h> 67#include <time.h>
68 68
69#ifndef PERL
70# include <signal.h> 69#include <signal.h>
71#endif
72 70
73#ifndef WIN32 71#ifndef WIN32
74# include <unistd.h> 72# include <unistd.h>
75# include <sys/time.h> 73# include <sys/time.h>
76# include <sys/wait.h> 74# include <sys/wait.h>
128#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 126#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
129#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 127#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
130#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 128#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
131/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 129/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
132 130
131#ifdef EV_H
132# include EV_H
133#else
133#include "ev.h" 134# include "ev.h"
135#endif
134 136
135#if __GNUC__ >= 3 137#if __GNUC__ >= 3
136# define expect(expr,value) __builtin_expect ((expr),(value)) 138# define expect(expr,value) __builtin_expect ((expr),(value))
137# define inline inline 139# define inline inline
138#else 140#else
150typedef struct ev_watcher_list *WL; 152typedef struct ev_watcher_list *WL;
151typedef struct ev_watcher_time *WT; 153typedef struct ev_watcher_time *WT;
152 154
153static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 155static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
154 156
155#if WIN32 157#include "ev_win32.c"
156/* note: the comment below could not be substantiated, but what would I care */
157/* MSDN says this is required to handle SIGFPE */
158volatile double SIGFPE_REQ = 0.0f;
159#endif
160 158
161/*****************************************************************************/ 159/*****************************************************************************/
162 160
163static void (*syserr_cb)(const char *msg); 161static void (*syserr_cb)(const char *msg);
164 162
221 int events; 219 int events;
222} ANPENDING; 220} ANPENDING;
223 221
224#if EV_MULTIPLICITY 222#if EV_MULTIPLICITY
225 223
226struct ev_loop 224 struct ev_loop
227{ 225 {
228# define VAR(name,decl) decl; 226 #define VAR(name,decl) decl;
229# include "ev_vars.h" 227 #include "ev_vars.h"
230};
231# undef VAR 228 #undef VAR
229 };
232# include "ev_wrap.h" 230 #include "ev_wrap.h"
231
232 struct ev_loop default_loop_struct;
233 static struct ev_loop *default_loop;
233 234
234#else 235#else
235 236
236# define VAR(name,decl) static decl; 237 #define VAR(name,decl) static decl;
237# include "ev_vars.h" 238 #include "ev_vars.h"
238# undef VAR 239 #undef VAR
240
241 static int default_loop;
239 242
240#endif 243#endif
241 244
242/*****************************************************************************/ 245/*****************************************************************************/
243 246
274ev_now (EV_P) 277ev_now (EV_P)
275{ 278{
276 return rt_now; 279 return rt_now;
277} 280}
278 281
279#define array_roundsize(base,n) ((n) | 4 & ~3) 282#define array_roundsize(type,n) ((n) | 4 & ~3)
280 283
281#define array_needsize(base,cur,cnt,init) \ 284#define array_needsize(type,base,cur,cnt,init) \
282 if (expect_false ((cnt) > cur)) \ 285 if (expect_false ((cnt) > cur)) \
283 { \ 286 { \
284 int newcnt = cur; \ 287 int newcnt = cur; \
285 do \ 288 do \
286 { \ 289 { \
287 newcnt = array_roundsize (base, newcnt << 1); \ 290 newcnt = array_roundsize (type, newcnt << 1); \
288 } \ 291 } \
289 while ((cnt) > newcnt); \ 292 while ((cnt) > newcnt); \
290 \ 293 \
291 base = ev_realloc (base, sizeof (*base) * (newcnt)); \ 294 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
292 init (base + cur, newcnt - cur); \ 295 init (base + cur, newcnt - cur); \
293 cur = newcnt; \ 296 cur = newcnt; \
294 } 297 }
295 298
296#define array_slim(stem) \ 299#define array_slim(type,stem) \
297 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 300 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
298 { \ 301 { \
299 stem ## max = array_roundsize (stem ## cnt >> 1); \ 302 stem ## max = array_roundsize (stem ## cnt >> 1); \
300 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ 303 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
301 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 304 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
302 } 305 }
303 306
304/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ 307/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
305/* bringing us everlasting joy in form of stupid extra macros that are not required in C */ 308/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
322 325
323 ++base; 326 ++base;
324 } 327 }
325} 328}
326 329
327static void 330void
328event (EV_P_ W w, int events) 331ev_feed_event (EV_P_ void *w, int revents)
329{ 332{
333 W w_ = (W)w;
334
330 if (w->pending) 335 if (w_->pending)
331 { 336 {
332 pendings [ABSPRI (w)][w->pending - 1].events |= events; 337 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
333 return; 338 return;
334 } 339 }
335 340
336 w->pending = ++pendingcnt [ABSPRI (w)]; 341 w_->pending = ++pendingcnt [ABSPRI (w_)];
337 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); 342 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void));
338 pendings [ABSPRI (w)][w->pending - 1].w = w; 343 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
339 pendings [ABSPRI (w)][w->pending - 1].events = events; 344 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
340} 345}
341 346
342static void 347static void
343queue_events (EV_P_ W *events, int eventcnt, int type) 348queue_events (EV_P_ W *events, int eventcnt, int type)
344{ 349{
345 int i; 350 int i;
346 351
347 for (i = 0; i < eventcnt; ++i) 352 for (i = 0; i < eventcnt; ++i)
348 event (EV_A_ events [i], type); 353 ev_feed_event (EV_A_ events [i], type);
349} 354}
350 355
351static void 356inline void
352fd_event (EV_P_ int fd, int events) 357fd_event (EV_P_ int fd, int revents)
353{ 358{
354 ANFD *anfd = anfds + fd; 359 ANFD *anfd = anfds + fd;
355 struct ev_io *w; 360 struct ev_io *w;
356 361
357 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 362 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
358 { 363 {
359 int ev = w->events & events; 364 int ev = w->events & revents;
360 365
361 if (ev) 366 if (ev)
362 event (EV_A_ (W)w, ev); 367 ev_feed_event (EV_A_ (W)w, ev);
363 } 368 }
369}
370
371void
372ev_feed_fd_event (EV_P_ int fd, int revents)
373{
374 fd_event (EV_A_ fd, revents);
364} 375}
365 376
366/*****************************************************************************/ 377/*****************************************************************************/
367 378
368static void 379static void
397 return; 408 return;
398 409
399 anfds [fd].reify = 1; 410 anfds [fd].reify = 1;
400 411
401 ++fdchangecnt; 412 ++fdchangecnt;
402 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); 413 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void));
403 fdchanges [fdchangecnt - 1] = fd; 414 fdchanges [fdchangecnt - 1] = fd;
404} 415}
405 416
406static void 417static void
407fd_kill (EV_P_ int fd) 418fd_kill (EV_P_ int fd)
409 struct ev_io *w; 420 struct ev_io *w;
410 421
411 while ((w = (struct ev_io *)anfds [fd].head)) 422 while ((w = (struct ev_io *)anfds [fd].head))
412 { 423 {
413 ev_io_stop (EV_A_ w); 424 ev_io_stop (EV_A_ w);
414 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 425 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
415 } 426 }
416} 427}
417 428
418static int 429static int
419fd_valid (int fd) 430fd_valid (int fd)
547 558
548 if (!gotsig) 559 if (!gotsig)
549 { 560 {
550 int old_errno = errno; 561 int old_errno = errno;
551 gotsig = 1; 562 gotsig = 1;
563#ifdef WIN32
564 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
565#else
552 write (sigpipe [1], &signum, 1); 566 write (sigpipe [1], &signum, 1);
567#endif
553 errno = old_errno; 568 errno = old_errno;
554 } 569 }
555} 570}
556 571
572void
573ev_feed_signal_event (EV_P_ int signum)
574{
575 WL w;
576
577#if EV_MULTIPLICITY
578 assert (("feeding signal events is only supported in the default loop", loop == default_loop));
579#endif
580
581 --signum;
582
583 if (signum < 0 || signum >= signalmax)
584 return;
585
586 signals [signum].gotsig = 0;
587
588 for (w = signals [signum].head; w; w = w->next)
589 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
590}
591
557static void 592static void
558sigcb (EV_P_ struct ev_io *iow, int revents) 593sigcb (EV_P_ struct ev_io *iow, int revents)
559{ 594{
560 WL w;
561 int signum; 595 int signum;
562 596
597#ifdef WIN32
598 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
599#else
563 read (sigpipe [0], &revents, 1); 600 read (sigpipe [0], &revents, 1);
601#endif
564 gotsig = 0; 602 gotsig = 0;
565 603
566 for (signum = signalmax; signum--; ) 604 for (signum = signalmax; signum--; )
567 if (signals [signum].gotsig) 605 if (signals [signum].gotsig)
568 { 606 ev_feed_signal_event (EV_A_ signum + 1);
569 signals [signum].gotsig = 0;
570
571 for (w = signals [signum].head; w; w = w->next)
572 event (EV_A_ (W)w, EV_SIGNAL);
573 }
574} 607}
575 608
576static void 609static void
577siginit (EV_P) 610siginit (EV_P)
578{ 611{
611 if (w->pid == pid || !w->pid) 644 if (w->pid == pid || !w->pid)
612 { 645 {
613 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 646 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
614 w->rpid = pid; 647 w->rpid = pid;
615 w->rstatus = status; 648 w->rstatus = status;
616 event (EV_A_ (W)w, EV_CHILD); 649 ev_feed_event (EV_A_ (W)w, EV_CHILD);
617 } 650 }
618} 651}
619 652
620static void 653static void
621childcb (EV_P_ struct ev_signal *sw, int revents) 654childcb (EV_P_ struct ev_signal *sw, int revents)
623 int pid, status; 656 int pid, status;
624 657
625 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 658 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
626 { 659 {
627 /* make sure we are called again until all childs have been reaped */ 660 /* make sure we are called again until all childs have been reaped */
628 event (EV_A_ (W)sw, EV_SIGNAL); 661 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
629 662
630 child_reap (EV_A_ sw, pid, pid, status); 663 child_reap (EV_A_ sw, pid, pid, status);
631 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 664 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
632 } 665 }
633} 666}
718#endif 751#endif
719#if EV_USE_SELECT 752#if EV_USE_SELECT
720 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 753 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
721#endif 754#endif
722 755
723 ev_watcher_init (&sigev, sigcb); 756 ev_init (&sigev, sigcb);
724 ev_set_priority (&sigev, EV_MAXPRI); 757 ev_set_priority (&sigev, EV_MAXPRI);
725 } 758 }
726} 759}
727 760
728void 761void
818} 851}
819 852
820#endif 853#endif
821 854
822#if EV_MULTIPLICITY 855#if EV_MULTIPLICITY
823struct ev_loop default_loop_struct;
824static struct ev_loop *default_loop;
825
826struct ev_loop * 856struct ev_loop *
827#else 857#else
828static int default_loop;
829
830int 858int
831#endif 859#endif
832ev_default_loop (int methods) 860ev_default_loop (int methods)
833{ 861{
834 if (sigpipe [0] == sigpipe [1]) 862 if (sigpipe [0] == sigpipe [1])
895 postfork = 1; 923 postfork = 1;
896} 924}
897 925
898/*****************************************************************************/ 926/*****************************************************************************/
899 927
928static int
929any_pending (EV_P)
930{
931 int pri;
932
933 for (pri = NUMPRI; pri--; )
934 if (pendingcnt [pri])
935 return 1;
936
937 return 0;
938}
939
900static void 940static void
901call_pending (EV_P) 941call_pending (EV_P)
902{ 942{
903 int pri; 943 int pri;
904 944
908 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 948 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
909 949
910 if (p->w) 950 if (p->w)
911 { 951 {
912 p->w->pending = 0; 952 p->w->pending = 0;
913 p->w->cb (EV_A_ p->w, p->events); 953 EV_CB_INVOKE (p->w, p->events);
914 } 954 }
915 } 955 }
916} 956}
917 957
918static void 958static void
932 downheap ((WT *)timers, timercnt, 0); 972 downheap ((WT *)timers, timercnt, 0);
933 } 973 }
934 else 974 else
935 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 975 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
936 976
937 event (EV_A_ (W)w, EV_TIMEOUT); 977 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
938 } 978 }
939} 979}
940 980
941static void 981static void
942periodics_reify (EV_P) 982periodics_reify (EV_P)
946 struct ev_periodic *w = periodics [0]; 986 struct ev_periodic *w = periodics [0];
947 987
948 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 988 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
949 989
950 /* first reschedule or stop timer */ 990 /* first reschedule or stop timer */
991 if (w->reschedule_cb)
992 {
993 ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001);
994
995 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now));
996 downheap ((WT *)periodics, periodiccnt, 0);
997 }
951 if (w->interval) 998 else if (w->interval)
952 { 999 {
953 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; 1000 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
954 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); 1001 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
955 downheap ((WT *)periodics, periodiccnt, 0); 1002 downheap ((WT *)periodics, periodiccnt, 0);
956 } 1003 }
957 else 1004 else
958 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1005 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
959 1006
960 event (EV_A_ (W)w, EV_PERIODIC); 1007 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
961 } 1008 }
962} 1009}
963 1010
964static void 1011static void
965periodics_reschedule (EV_P) 1012periodics_reschedule (EV_P)
969 /* adjust periodics after time jump */ 1016 /* adjust periodics after time jump */
970 for (i = 0; i < periodiccnt; ++i) 1017 for (i = 0; i < periodiccnt; ++i)
971 { 1018 {
972 struct ev_periodic *w = periodics [i]; 1019 struct ev_periodic *w = periodics [i];
973 1020
1021 if (w->reschedule_cb)
1022 ((WT)w)->at = w->reschedule_cb (w, rt_now);
974 if (w->interval) 1023 else if (w->interval)
975 {
976 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1024 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
977
978 if (fabs (diff) >= 1e-4)
979 {
980 ev_periodic_stop (EV_A_ w);
981 ev_periodic_start (EV_A_ w);
982
983 i = 0; /* restart loop, inefficient, but time jumps should be rare */
984 }
985 }
986 } 1025 }
1026
1027 /* now rebuild the heap */
1028 for (i = periodiccnt >> 1; i--; )
1029 downheap ((WT *)periodics, periodiccnt, i);
987} 1030}
988 1031
989inline int 1032inline int
990time_update_monotonic (EV_P) 1033time_update_monotonic (EV_P)
991{ 1034{
1087 /* update fd-related kernel structures */ 1130 /* update fd-related kernel structures */
1088 fd_reify (EV_A); 1131 fd_reify (EV_A);
1089 1132
1090 /* calculate blocking time */ 1133 /* calculate blocking time */
1091 1134
1092 /* we only need this for !monotonic clockor timers, but as we basically 1135 /* we only need this for !monotonic clock or timers, but as we basically
1093 always have timers, we just calculate it always */ 1136 always have timers, we just calculate it always */
1094#if EV_USE_MONOTONIC 1137#if EV_USE_MONOTONIC
1095 if (expect_true (have_monotonic)) 1138 if (expect_true (have_monotonic))
1096 time_update_monotonic (EV_A); 1139 time_update_monotonic (EV_A);
1097 else 1140 else
1130 /* queue pending timers and reschedule them */ 1173 /* queue pending timers and reschedule them */
1131 timers_reify (EV_A); /* relative timers called last */ 1174 timers_reify (EV_A); /* relative timers called last */
1132 periodics_reify (EV_A); /* absolute timers called first */ 1175 periodics_reify (EV_A); /* absolute timers called first */
1133 1176
1134 /* queue idle watchers unless io or timers are pending */ 1177 /* queue idle watchers unless io or timers are pending */
1135 if (!pendingcnt) 1178 if (idlecnt && !any_pending (EV_A))
1136 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1179 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1137 1180
1138 /* queue check watchers, to be executed first */ 1181 /* queue check watchers, to be executed first */
1139 if (checkcnt) 1182 if (checkcnt)
1140 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1183 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1215 return; 1258 return;
1216 1259
1217 assert (("ev_io_start called with negative fd", fd >= 0)); 1260 assert (("ev_io_start called with negative fd", fd >= 0));
1218 1261
1219 ev_start (EV_A_ (W)w, 1); 1262 ev_start (EV_A_ (W)w, 1);
1220 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 1263 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
1221 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1264 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1222 1265
1223 fd_change (EV_A_ fd); 1266 fd_change (EV_A_ fd);
1224} 1267}
1225 1268
1245 ((WT)w)->at += mn_now; 1288 ((WT)w)->at += mn_now;
1246 1289
1247 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1290 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1248 1291
1249 ev_start (EV_A_ (W)w, ++timercnt); 1292 ev_start (EV_A_ (W)w, ++timercnt);
1250 array_needsize (timers, timermax, timercnt, (void)); 1293 array_needsize (struct ev_timer *, timers, timermax, timercnt, (void));
1251 timers [timercnt - 1] = w; 1294 timers [timercnt - 1] = w;
1252 upheap ((WT *)timers, timercnt - 1); 1295 upheap ((WT *)timers, timercnt - 1);
1253 1296
1254 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1297 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1255} 1298}
1295ev_periodic_start (EV_P_ struct ev_periodic *w) 1338ev_periodic_start (EV_P_ struct ev_periodic *w)
1296{ 1339{
1297 if (ev_is_active (w)) 1340 if (ev_is_active (w))
1298 return; 1341 return;
1299 1342
1343 if (w->reschedule_cb)
1344 ((WT)w)->at = w->reschedule_cb (w, rt_now);
1345 else if (w->interval)
1346 {
1300 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1347 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1301
1302 /* this formula differs from the one in periodic_reify because we do not always round up */ 1348 /* this formula differs from the one in periodic_reify because we do not always round up */
1303 if (w->interval)
1304 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1349 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1350 }
1305 1351
1306 ev_start (EV_A_ (W)w, ++periodiccnt); 1352 ev_start (EV_A_ (W)w, ++periodiccnt);
1307 array_needsize (periodics, periodicmax, periodiccnt, (void)); 1353 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void));
1308 periodics [periodiccnt - 1] = w; 1354 periodics [periodiccnt - 1] = w;
1309 upheap ((WT *)periodics, periodiccnt - 1); 1355 upheap ((WT *)periodics, periodiccnt - 1);
1310 1356
1311 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1357 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1312} 1358}
1328 1374
1329 ev_stop (EV_A_ (W)w); 1375 ev_stop (EV_A_ (W)w);
1330} 1376}
1331 1377
1332void 1378void
1379ev_periodic_again (EV_P_ struct ev_periodic *w)
1380{
1381 ev_periodic_stop (EV_A_ w);
1382 ev_periodic_start (EV_A_ w);
1383}
1384
1385void
1333ev_idle_start (EV_P_ struct ev_idle *w) 1386ev_idle_start (EV_P_ struct ev_idle *w)
1334{ 1387{
1335 if (ev_is_active (w)) 1388 if (ev_is_active (w))
1336 return; 1389 return;
1337 1390
1338 ev_start (EV_A_ (W)w, ++idlecnt); 1391 ev_start (EV_A_ (W)w, ++idlecnt);
1339 array_needsize (idles, idlemax, idlecnt, (void)); 1392 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void));
1340 idles [idlecnt - 1] = w; 1393 idles [idlecnt - 1] = w;
1341} 1394}
1342 1395
1343void 1396void
1344ev_idle_stop (EV_P_ struct ev_idle *w) 1397ev_idle_stop (EV_P_ struct ev_idle *w)
1356{ 1409{
1357 if (ev_is_active (w)) 1410 if (ev_is_active (w))
1358 return; 1411 return;
1359 1412
1360 ev_start (EV_A_ (W)w, ++preparecnt); 1413 ev_start (EV_A_ (W)w, ++preparecnt);
1361 array_needsize (prepares, preparemax, preparecnt, (void)); 1414 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void));
1362 prepares [preparecnt - 1] = w; 1415 prepares [preparecnt - 1] = w;
1363} 1416}
1364 1417
1365void 1418void
1366ev_prepare_stop (EV_P_ struct ev_prepare *w) 1419ev_prepare_stop (EV_P_ struct ev_prepare *w)
1378{ 1431{
1379 if (ev_is_active (w)) 1432 if (ev_is_active (w))
1380 return; 1433 return;
1381 1434
1382 ev_start (EV_A_ (W)w, ++checkcnt); 1435 ev_start (EV_A_ (W)w, ++checkcnt);
1383 array_needsize (checks, checkmax, checkcnt, (void)); 1436 array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void));
1384 checks [checkcnt - 1] = w; 1437 checks [checkcnt - 1] = w;
1385} 1438}
1386 1439
1387void 1440void
1388ev_check_stop (EV_P_ struct ev_check *w) 1441ev_check_stop (EV_P_ struct ev_check *w)
1409 return; 1462 return;
1410 1463
1411 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1464 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1412 1465
1413 ev_start (EV_A_ (W)w, 1); 1466 ev_start (EV_A_ (W)w, 1);
1414 array_needsize (signals, signalmax, w->signum, signals_init); 1467 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1415 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1468 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1416 1469
1417 if (!((WL)w)->next) 1470 if (!((WL)w)->next)
1418 { 1471 {
1419#if WIN32 1472#if WIN32
1502} 1555}
1503 1556
1504void 1557void
1505ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1558ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1506{ 1559{
1507 struct ev_once *once = ev_malloc (sizeof (struct ev_once)); 1560 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1508 1561
1509 if (!once) 1562 if (!once)
1510 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1563 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1511 else 1564 else
1512 { 1565 {
1513 once->cb = cb; 1566 once->cb = cb;
1514 once->arg = arg; 1567 once->arg = arg;
1515 1568
1516 ev_watcher_init (&once->io, once_cb_io); 1569 ev_init (&once->io, once_cb_io);
1517 if (fd >= 0) 1570 if (fd >= 0)
1518 { 1571 {
1519 ev_io_set (&once->io, fd, events); 1572 ev_io_set (&once->io, fd, events);
1520 ev_io_start (EV_A_ &once->io); 1573 ev_io_start (EV_A_ &once->io);
1521 } 1574 }
1522 1575
1523 ev_watcher_init (&once->to, once_cb_to); 1576 ev_init (&once->to, once_cb_to);
1524 if (timeout >= 0.) 1577 if (timeout >= 0.)
1525 { 1578 {
1526 ev_timer_set (&once->to, timeout, 0.); 1579 ev_timer_set (&once->to, timeout, 0.);
1527 ev_timer_start (EV_A_ &once->to); 1580 ev_timer_start (EV_A_ &once->to);
1528 } 1581 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines