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

Comparing libev/ev.c (file contents):
Revision 1.72 by root, Tue Nov 6 16:09:37 2007 UTC vs.
Revision 1.80 by root, Fri Nov 9 15:30:59 2007 UTC

148typedef struct ev_watcher_list *WL; 148typedef struct ev_watcher_list *WL;
149typedef struct ev_watcher_time *WT; 149typedef struct ev_watcher_time *WT;
150 150
151static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 151static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
152 152
153#if WIN32 153#include "ev_win32.c"
154/* note: the comment below could not be substantiated, but what would I care */
155/* MSDN says this is required to handle SIGFPE */
156volatile double SIGFPE_REQ = 0.0f;
157
158static int
159ev_socketpair_tcp (int filedes [2])
160{
161 struct sockaddr_in addr = { 0 };
162 int addr_size = sizeof (addr);
163 SOCKET listener;
164 SOCKET sock [2] = { -1, -1 };
165
166 if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
167 return -1;
168
169 addr.sin_family = AF_INET;
170 addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
171 addr.sin_port = 0;
172
173 if (bind (listener, (struct sockaddr *)&addr, addr_size))
174 goto fail;
175
176 if (getsockname(listener, (struct sockaddr *)&addr, &addr_size))
177 goto fail;
178
179 if (listen (listener, 1))
180 goto fail;
181
182 if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
183 goto fail;
184
185 if (connect (sock[0], (struct sockaddr *)&addr, addr_size))
186 goto fail;
187
188 if ((sock[1] = accept (listener, 0, 0)) < 0)
189 goto fail;
190
191 closesocket (listener);
192
193 filedes [0] = sock [0];
194 filedes [1] = sock [1];
195
196 return 0;
197
198fail:
199 closesocket (listener);
200
201 if (sock [0] != INVALID_SOCKET) closesocket (sock [0]);
202 if (sock [1] != INVALID_SOCKET) closesocket (sock [1]);
203
204 return -1;
205}
206
207# define ev_pipe(filedes) ev_socketpair_tcp (filedes)
208#else
209# define ev_pipe(filedes) pipe (filedes)
210#endif
211 154
212/*****************************************************************************/ 155/*****************************************************************************/
213 156
214static void (*syserr_cb)(const char *msg); 157static void (*syserr_cb)(const char *msg);
215 158
272 int events; 215 int events;
273} ANPENDING; 216} ANPENDING;
274 217
275#if EV_MULTIPLICITY 218#if EV_MULTIPLICITY
276 219
277struct ev_loop 220 struct ev_loop
278{ 221 {
279# define VAR(name,decl) decl; 222 #define VAR(name,decl) decl;
280# include "ev_vars.h" 223 #include "ev_vars.h"
281};
282# undef VAR 224 #undef VAR
225 };
283# include "ev_wrap.h" 226 #include "ev_wrap.h"
227
228 struct ev_loop default_loop_struct;
229 static struct ev_loop *default_loop;
284 230
285#else 231#else
286 232
287# define VAR(name,decl) static decl; 233 #define VAR(name,decl) static decl;
288# include "ev_vars.h" 234 #include "ev_vars.h"
289# undef VAR 235 #undef VAR
236
237 static int default_loop;
290 238
291#endif 239#endif
292 240
293/*****************************************************************************/ 241/*****************************************************************************/
294 242
325ev_now (EV_P) 273ev_now (EV_P)
326{ 274{
327 return rt_now; 275 return rt_now;
328} 276}
329 277
330#define array_roundsize(base,n) ((n) | 4 & ~3) 278#define array_roundsize(type,n) ((n) | 4 & ~3)
331 279
332#define array_needsize(base,cur,cnt,init) \ 280#define array_needsize(type,base,cur,cnt,init) \
333 if (expect_false ((cnt) > cur)) \ 281 if (expect_false ((cnt) > cur)) \
334 { \ 282 { \
335 int newcnt = cur; \ 283 int newcnt = cur; \
336 do \ 284 do \
337 { \ 285 { \
338 newcnt = array_roundsize (base, newcnt << 1); \ 286 newcnt = array_roundsize (type, newcnt << 1); \
339 } \ 287 } \
340 while ((cnt) > newcnt); \ 288 while ((cnt) > newcnt); \
341 \ 289 \
342 base = ev_realloc (base, sizeof (*base) * (newcnt)); \ 290 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
343 init (base + cur, newcnt - cur); \ 291 init (base + cur, newcnt - cur); \
344 cur = newcnt; \ 292 cur = newcnt; \
345 } 293 }
346 294
347#define array_slim(stem) \ 295#define array_slim(type,stem) \
348 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 296 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
349 { \ 297 { \
350 stem ## max = array_roundsize (stem ## cnt >> 1); \ 298 stem ## max = array_roundsize (stem ## cnt >> 1); \
351 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ 299 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
352 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 300 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
353 } 301 }
354 302
355/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ 303/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
356/* bringing us everlasting joy in form of stupid extra macros that are not required in C */ 304/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
373 321
374 ++base; 322 ++base;
375 } 323 }
376} 324}
377 325
378static void 326void
379event (EV_P_ W w, int events) 327ev_feed_event (EV_P_ void *w, int revents)
380{ 328{
329 W w_ = (W)w;
330
381 if (w->pending) 331 if (w_->pending)
382 { 332 {
383 pendings [ABSPRI (w)][w->pending - 1].events |= events; 333 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
384 return; 334 return;
385 } 335 }
386 336
387 w->pending = ++pendingcnt [ABSPRI (w)]; 337 w_->pending = ++pendingcnt [ABSPRI (w_)];
388 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); 338 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void));
389 pendings [ABSPRI (w)][w->pending - 1].w = w; 339 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
390 pendings [ABSPRI (w)][w->pending - 1].events = events; 340 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
391} 341}
392 342
393static void 343static void
394queue_events (EV_P_ W *events, int eventcnt, int type) 344queue_events (EV_P_ W *events, int eventcnt, int type)
395{ 345{
396 int i; 346 int i;
397 347
398 for (i = 0; i < eventcnt; ++i) 348 for (i = 0; i < eventcnt; ++i)
399 event (EV_A_ events [i], type); 349 ev_feed_event (EV_A_ events [i], type);
400} 350}
401 351
402static void 352inline void
403fd_event (EV_P_ int fd, int events) 353fd_event (EV_P_ int fd, int revents)
404{ 354{
405 ANFD *anfd = anfds + fd; 355 ANFD *anfd = anfds + fd;
406 struct ev_io *w; 356 struct ev_io *w;
407 357
408 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 358 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
409 { 359 {
410 int ev = w->events & events; 360 int ev = w->events & revents;
411 361
412 if (ev) 362 if (ev)
413 event (EV_A_ (W)w, ev); 363 ev_feed_event (EV_A_ (W)w, ev);
414 } 364 }
365}
366
367void
368ev_feed_fd_event (EV_P_ int fd, int revents)
369{
370 fd_event (EV_A_ fd, revents);
415} 371}
416 372
417/*****************************************************************************/ 373/*****************************************************************************/
418 374
419static void 375static void
448 return; 404 return;
449 405
450 anfds [fd].reify = 1; 406 anfds [fd].reify = 1;
451 407
452 ++fdchangecnt; 408 ++fdchangecnt;
453 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); 409 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void));
454 fdchanges [fdchangecnt - 1] = fd; 410 fdchanges [fdchangecnt - 1] = fd;
455} 411}
456 412
457static void 413static void
458fd_kill (EV_P_ int fd) 414fd_kill (EV_P_ int fd)
460 struct ev_io *w; 416 struct ev_io *w;
461 417
462 while ((w = (struct ev_io *)anfds [fd].head)) 418 while ((w = (struct ev_io *)anfds [fd].head))
463 { 419 {
464 ev_io_stop (EV_A_ w); 420 ev_io_stop (EV_A_ w);
465 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 421 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
466 } 422 }
467} 423}
468 424
469static int 425static int
470fd_valid (int fd) 426fd_valid (int fd)
598 554
599 if (!gotsig) 555 if (!gotsig)
600 { 556 {
601 int old_errno = errno; 557 int old_errno = errno;
602 gotsig = 1; 558 gotsig = 1;
559#ifdef WIN32
560 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
561#else
603 write (sigpipe [1], &signum, 1); 562 write (sigpipe [1], &signum, 1);
563#endif
604 errno = old_errno; 564 errno = old_errno;
605 } 565 }
606} 566}
607 567
568void
569ev_feed_signal_event (EV_P_ int signum)
570{
571 WL w;
572
573#if EV_MULTIPLICITY
574 assert (("feeding signal events is only supported in the default loop", loop == default_loop));
575#endif
576
577 --signum;
578
579 if (signum < 0 || signum >= signalmax)
580 return;
581
582 signals [signum].gotsig = 0;
583
584 for (w = signals [signum].head; w; w = w->next)
585 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
586}
587
608static void 588static void
609sigcb (EV_P_ struct ev_io *iow, int revents) 589sigcb (EV_P_ struct ev_io *iow, int revents)
610{ 590{
611 WL w;
612 int signum; 591 int signum;
613 592
593#ifdef WIN32
594 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
595#else
614 read (sigpipe [0], &revents, 1); 596 read (sigpipe [0], &revents, 1);
597#endif
615 gotsig = 0; 598 gotsig = 0;
616 599
617 for (signum = signalmax; signum--; ) 600 for (signum = signalmax; signum--; )
618 if (signals [signum].gotsig) 601 if (signals [signum].gotsig)
619 { 602 ev_feed_signal_event (EV_A_ signum + 1);
620 signals [signum].gotsig = 0;
621
622 for (w = signals [signum].head; w; w = w->next)
623 event (EV_A_ (W)w, EV_SIGNAL);
624 }
625} 603}
626 604
627static void 605static void
628siginit (EV_P) 606siginit (EV_P)
629{ 607{
662 if (w->pid == pid || !w->pid) 640 if (w->pid == pid || !w->pid)
663 { 641 {
664 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 642 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
665 w->rpid = pid; 643 w->rpid = pid;
666 w->rstatus = status; 644 w->rstatus = status;
667 event (EV_A_ (W)w, EV_CHILD); 645 ev_feed_event (EV_A_ (W)w, EV_CHILD);
668 } 646 }
669} 647}
670 648
671static void 649static void
672childcb (EV_P_ struct ev_signal *sw, int revents) 650childcb (EV_P_ struct ev_signal *sw, int revents)
674 int pid, status; 652 int pid, status;
675 653
676 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 654 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
677 { 655 {
678 /* make sure we are called again until all childs have been reaped */ 656 /* make sure we are called again until all childs have been reaped */
679 event (EV_A_ (W)sw, EV_SIGNAL); 657 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
680 658
681 child_reap (EV_A_ sw, pid, pid, status); 659 child_reap (EV_A_ sw, pid, pid, status);
682 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 660 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
683 } 661 }
684} 662}
828 ev_ref (EV_A); 806 ev_ref (EV_A);
829 ev_io_stop (EV_A_ &sigev); 807 ev_io_stop (EV_A_ &sigev);
830 close (sigpipe [0]); 808 close (sigpipe [0]);
831 close (sigpipe [1]); 809 close (sigpipe [1]);
832 810
833 while (ev_pipe (sigpipe)) 811 while (pipe (sigpipe))
834 syserr ("(libev) error creating pipe"); 812 syserr ("(libev) error creating pipe");
835 813
836 siginit (EV_A); 814 siginit (EV_A);
837 } 815 }
838 816
869} 847}
870 848
871#endif 849#endif
872 850
873#if EV_MULTIPLICITY 851#if EV_MULTIPLICITY
874struct ev_loop default_loop_struct;
875static struct ev_loop *default_loop;
876
877struct ev_loop * 852struct ev_loop *
878#else 853#else
879static int default_loop;
880
881int 854int
882#endif 855#endif
883ev_default_loop (int methods) 856ev_default_loop (int methods)
884{ 857{
885 if (sigpipe [0] == sigpipe [1]) 858 if (sigpipe [0] == sigpipe [1])
886 if (ev_pipe (sigpipe)) 859 if (pipe (sigpipe))
887 return 0; 860 return 0;
888 861
889 if (!default_loop) 862 if (!default_loop)
890 { 863 {
891#if EV_MULTIPLICITY 864#if EV_MULTIPLICITY
945 if (method) 918 if (method)
946 postfork = 1; 919 postfork = 1;
947} 920}
948 921
949/*****************************************************************************/ 922/*****************************************************************************/
923
924static int
925any_pending (EV_P)
926{
927 int pri;
928
929 for (pri = NUMPRI; pri--; )
930 if (pendingcnt [pri])
931 return 1;
932
933 return 0;
934}
950 935
951static void 936static void
952call_pending (EV_P) 937call_pending (EV_P)
953{ 938{
954 int pri; 939 int pri;
983 downheap ((WT *)timers, timercnt, 0); 968 downheap ((WT *)timers, timercnt, 0);
984 } 969 }
985 else 970 else
986 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 971 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
987 972
988 event (EV_A_ (W)w, EV_TIMEOUT); 973 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
989 } 974 }
990} 975}
991 976
992static void 977static void
993periodics_reify (EV_P) 978periodics_reify (EV_P)
997 struct ev_periodic *w = periodics [0]; 982 struct ev_periodic *w = periodics [0];
998 983
999 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 984 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1000 985
1001 /* first reschedule or stop timer */ 986 /* first reschedule or stop timer */
987 if (w->reschedule_cb)
988 {
989 ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001);
990
991 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now));
992 downheap ((WT *)periodics, periodiccnt, 0);
993 }
1002 if (w->interval) 994 else if (w->interval)
1003 { 995 {
1004 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; 996 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
1005 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); 997 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
1006 downheap ((WT *)periodics, periodiccnt, 0); 998 downheap ((WT *)periodics, periodiccnt, 0);
1007 } 999 }
1008 else 1000 else
1009 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1001 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1010 1002
1011 event (EV_A_ (W)w, EV_PERIODIC); 1003 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1012 } 1004 }
1013} 1005}
1014 1006
1015static void 1007static void
1016periodics_reschedule (EV_P) 1008periodics_reschedule (EV_P)
1020 /* adjust periodics after time jump */ 1012 /* adjust periodics after time jump */
1021 for (i = 0; i < periodiccnt; ++i) 1013 for (i = 0; i < periodiccnt; ++i)
1022 { 1014 {
1023 struct ev_periodic *w = periodics [i]; 1015 struct ev_periodic *w = periodics [i];
1024 1016
1017 if (w->reschedule_cb)
1018 ((WT)w)->at = w->reschedule_cb (w, rt_now);
1025 if (w->interval) 1019 else if (w->interval)
1026 {
1027 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1020 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1028
1029 if (fabs (diff) >= 1e-4)
1030 {
1031 ev_periodic_stop (EV_A_ w);
1032 ev_periodic_start (EV_A_ w);
1033
1034 i = 0; /* restart loop, inefficient, but time jumps should be rare */
1035 }
1036 }
1037 } 1021 }
1022
1023 /* now rebuild the heap */
1024 for (i = periodiccnt >> 1; i--; )
1025 downheap ((WT *)periodics, periodiccnt, i);
1038} 1026}
1039 1027
1040inline int 1028inline int
1041time_update_monotonic (EV_P) 1029time_update_monotonic (EV_P)
1042{ 1030{
1138 /* update fd-related kernel structures */ 1126 /* update fd-related kernel structures */
1139 fd_reify (EV_A); 1127 fd_reify (EV_A);
1140 1128
1141 /* calculate blocking time */ 1129 /* calculate blocking time */
1142 1130
1143 /* we only need this for !monotonic clockor timers, but as we basically 1131 /* we only need this for !monotonic clock or timers, but as we basically
1144 always have timers, we just calculate it always */ 1132 always have timers, we just calculate it always */
1145#if EV_USE_MONOTONIC 1133#if EV_USE_MONOTONIC
1146 if (expect_true (have_monotonic)) 1134 if (expect_true (have_monotonic))
1147 time_update_monotonic (EV_A); 1135 time_update_monotonic (EV_A);
1148 else 1136 else
1181 /* queue pending timers and reschedule them */ 1169 /* queue pending timers and reschedule them */
1182 timers_reify (EV_A); /* relative timers called last */ 1170 timers_reify (EV_A); /* relative timers called last */
1183 periodics_reify (EV_A); /* absolute timers called first */ 1171 periodics_reify (EV_A); /* absolute timers called first */
1184 1172
1185 /* queue idle watchers unless io or timers are pending */ 1173 /* queue idle watchers unless io or timers are pending */
1186 if (!pendingcnt) 1174 if (idlecnt && !any_pending (EV_A))
1187 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1175 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1188 1176
1189 /* queue check watchers, to be executed first */ 1177 /* queue check watchers, to be executed first */
1190 if (checkcnt) 1178 if (checkcnt)
1191 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1179 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1266 return; 1254 return;
1267 1255
1268 assert (("ev_io_start called with negative fd", fd >= 0)); 1256 assert (("ev_io_start called with negative fd", fd >= 0));
1269 1257
1270 ev_start (EV_A_ (W)w, 1); 1258 ev_start (EV_A_ (W)w, 1);
1271 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 1259 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
1272 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1260 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1273 1261
1274 fd_change (EV_A_ fd); 1262 fd_change (EV_A_ fd);
1275} 1263}
1276 1264
1296 ((WT)w)->at += mn_now; 1284 ((WT)w)->at += mn_now;
1297 1285
1298 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1286 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1299 1287
1300 ev_start (EV_A_ (W)w, ++timercnt); 1288 ev_start (EV_A_ (W)w, ++timercnt);
1301 array_needsize (timers, timermax, timercnt, (void)); 1289 array_needsize (struct ev_timer *, timers, timermax, timercnt, (void));
1302 timers [timercnt - 1] = w; 1290 timers [timercnt - 1] = w;
1303 upheap ((WT *)timers, timercnt - 1); 1291 upheap ((WT *)timers, timercnt - 1);
1304 1292
1305 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1293 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1306} 1294}
1346ev_periodic_start (EV_P_ struct ev_periodic *w) 1334ev_periodic_start (EV_P_ struct ev_periodic *w)
1347{ 1335{
1348 if (ev_is_active (w)) 1336 if (ev_is_active (w))
1349 return; 1337 return;
1350 1338
1339 if (w->reschedule_cb)
1340 ((WT)w)->at = w->reschedule_cb (w, rt_now);
1341 else if (w->interval)
1342 {
1351 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1343 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1352
1353 /* this formula differs from the one in periodic_reify because we do not always round up */ 1344 /* this formula differs from the one in periodic_reify because we do not always round up */
1354 if (w->interval)
1355 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1345 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1346 }
1356 1347
1357 ev_start (EV_A_ (W)w, ++periodiccnt); 1348 ev_start (EV_A_ (W)w, ++periodiccnt);
1358 array_needsize (periodics, periodicmax, periodiccnt, (void)); 1349 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void));
1359 periodics [periodiccnt - 1] = w; 1350 periodics [periodiccnt - 1] = w;
1360 upheap ((WT *)periodics, periodiccnt - 1); 1351 upheap ((WT *)periodics, periodiccnt - 1);
1361 1352
1362 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1353 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1363} 1354}
1379 1370
1380 ev_stop (EV_A_ (W)w); 1371 ev_stop (EV_A_ (W)w);
1381} 1372}
1382 1373
1383void 1374void
1375ev_periodic_again (EV_P_ struct ev_periodic *w)
1376{
1377 ev_periodic_stop (EV_A_ w);
1378 ev_periodic_start (EV_A_ w);
1379}
1380
1381void
1384ev_idle_start (EV_P_ struct ev_idle *w) 1382ev_idle_start (EV_P_ struct ev_idle *w)
1385{ 1383{
1386 if (ev_is_active (w)) 1384 if (ev_is_active (w))
1387 return; 1385 return;
1388 1386
1389 ev_start (EV_A_ (W)w, ++idlecnt); 1387 ev_start (EV_A_ (W)w, ++idlecnt);
1390 array_needsize (idles, idlemax, idlecnt, (void)); 1388 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void));
1391 idles [idlecnt - 1] = w; 1389 idles [idlecnt - 1] = w;
1392} 1390}
1393 1391
1394void 1392void
1395ev_idle_stop (EV_P_ struct ev_idle *w) 1393ev_idle_stop (EV_P_ struct ev_idle *w)
1407{ 1405{
1408 if (ev_is_active (w)) 1406 if (ev_is_active (w))
1409 return; 1407 return;
1410 1408
1411 ev_start (EV_A_ (W)w, ++preparecnt); 1409 ev_start (EV_A_ (W)w, ++preparecnt);
1412 array_needsize (prepares, preparemax, preparecnt, (void)); 1410 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void));
1413 prepares [preparecnt - 1] = w; 1411 prepares [preparecnt - 1] = w;
1414} 1412}
1415 1413
1416void 1414void
1417ev_prepare_stop (EV_P_ struct ev_prepare *w) 1415ev_prepare_stop (EV_P_ struct ev_prepare *w)
1429{ 1427{
1430 if (ev_is_active (w)) 1428 if (ev_is_active (w))
1431 return; 1429 return;
1432 1430
1433 ev_start (EV_A_ (W)w, ++checkcnt); 1431 ev_start (EV_A_ (W)w, ++checkcnt);
1434 array_needsize (checks, checkmax, checkcnt, (void)); 1432 array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void));
1435 checks [checkcnt - 1] = w; 1433 checks [checkcnt - 1] = w;
1436} 1434}
1437 1435
1438void 1436void
1439ev_check_stop (EV_P_ struct ev_check *w) 1437ev_check_stop (EV_P_ struct ev_check *w)
1460 return; 1458 return;
1461 1459
1462 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1460 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1463 1461
1464 ev_start (EV_A_ (W)w, 1); 1462 ev_start (EV_A_ (W)w, 1);
1465 array_needsize (signals, signalmax, w->signum, signals_init); 1463 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1466 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1464 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1467 1465
1468 if (!((WL)w)->next) 1466 if (!((WL)w)->next)
1469 { 1467 {
1470#if WIN32 1468#if WIN32
1553} 1551}
1554 1552
1555void 1553void
1556ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1554ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1557{ 1555{
1558 struct ev_once *once = ev_malloc (sizeof (struct ev_once)); 1556 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1559 1557
1560 if (!once) 1558 if (!once)
1561 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1559 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1562 else 1560 else
1563 { 1561 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines