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

Comparing libev/ev.c (file contents):
Revision 1.139 by root, Sun Nov 25 09:24:37 2007 UTC vs.
Revision 1.151 by root, Tue Nov 27 19:59:08 2007 UTC

111#include <time.h> 111#include <time.h>
112 112
113#include <signal.h> 113#include <signal.h>
114 114
115#ifndef _WIN32 115#ifndef _WIN32
116# include <unistd.h>
117# include <sys/time.h> 116# include <sys/time.h>
118# include <sys/wait.h> 117# include <sys/wait.h>
118# include <unistd.h>
119#else 119#else
120# define WIN32_LEAN_AND_MEAN 120# define WIN32_LEAN_AND_MEAN
121# include <windows.h> 121# include <windows.h>
122# ifndef EV_SELECT_IS_WINSOCKET 122# ifndef EV_SELECT_IS_WINSOCKET
123# define EV_SELECT_IS_WINSOCKET 1 123# define EV_SELECT_IS_WINSOCKET 1
156 156
157#ifndef EV_USE_PORT 157#ifndef EV_USE_PORT
158# define EV_USE_PORT 0 158# define EV_USE_PORT 0
159#endif 159#endif
160 160
161#ifndef EV_PID_HASHSIZE
162# if EV_MINIMAL
163# define EV_PID_HASHSIZE 1
164# else
165# define EV_PID_HASHSIZE 16
166# endif
167#endif
168
161/**/ 169/**/
162 170
163#ifndef CLOCK_MONOTONIC 171#ifndef CLOCK_MONOTONIC
164# undef EV_USE_MONOTONIC 172# undef EV_USE_MONOTONIC
165# define EV_USE_MONOTONIC 0 173# define EV_USE_MONOTONIC 0
176 184
177/**/ 185/**/
178 186
179#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 187#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
180#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 188#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
181#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
182/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ 189/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
183 190
184#ifdef EV_H 191#ifdef EV_H
185# include EV_H 192# include EV_H
186#else 193#else
187# include "ev.h" 194# include "ev.h"
188#endif 195#endif
189 196
190#if __GNUC__ >= 3 197#if __GNUC__ >= 3
191# define expect(expr,value) __builtin_expect ((expr),(value)) 198# define expect(expr,value) __builtin_expect ((expr),(value))
199# define inline_size static inline /* inline for codesize */
200# if EV_MINIMAL
201# define noinline __attribute__ ((noinline))
202# define inline_speed static noinline
203# else
204# define noinline
192# define inline static inline 205# define inline_speed static inline
206# endif
193#else 207#else
194# define expect(expr,value) (expr) 208# define expect(expr,value) (expr)
209# define inline_speed static
195# define inline static 210# define inline_size static
211# define noinline
196#endif 212#endif
197 213
198#define expect_false(expr) expect ((expr) != 0, 0) 214#define expect_false(expr) expect ((expr) != 0, 0)
199#define expect_true(expr) expect ((expr) != 0, 1) 215#define expect_true(expr) expect ((expr) != 0, 1)
200 216
216 232
217/*****************************************************************************/ 233/*****************************************************************************/
218 234
219static void (*syserr_cb)(const char *msg); 235static void (*syserr_cb)(const char *msg);
220 236
237void
221void ev_set_syserr_cb (void (*cb)(const char *msg)) 238ev_set_syserr_cb (void (*cb)(const char *msg))
222{ 239{
223 syserr_cb = cb; 240 syserr_cb = cb;
224} 241}
225 242
226static void 243static void noinline
227syserr (const char *msg) 244syserr (const char *msg)
228{ 245{
229 if (!msg) 246 if (!msg)
230 msg = "(libev) system error"; 247 msg = "(libev) system error";
231 248
236 perror (msg); 253 perror (msg);
237 abort (); 254 abort ();
238 } 255 }
239} 256}
240 257
241static void *(*alloc)(void *ptr, long size); 258static void *(*alloc)(void *ptr, size_t size) = realloc;
242 259
260void
243void ev_set_allocator (void *(*cb)(void *ptr, long size)) 261ev_set_allocator (void *(*cb)(void *ptr, size_t size))
244{ 262{
245 alloc = cb; 263 alloc = cb;
246} 264}
247 265
248static void * 266inline_speed void *
249ev_realloc (void *ptr, long size) 267ev_realloc (void *ptr, size_t size)
250{ 268{
251 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); 269 ptr = alloc (ptr, size);
252 270
253 if (!ptr && size) 271 if (!ptr && size)
254 { 272 {
255 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 273 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", (long)size);
256 abort (); 274 abort ();
257 } 275 }
258 276
259 return ptr; 277 return ptr;
260} 278}
320 gettimeofday (&tv, 0); 338 gettimeofday (&tv, 0);
321 return tv.tv_sec + tv.tv_usec * 1e-6; 339 return tv.tv_sec + tv.tv_usec * 1e-6;
322#endif 340#endif
323} 341}
324 342
325inline ev_tstamp 343ev_tstamp inline_size
326get_clock (void) 344get_clock (void)
327{ 345{
328#if EV_USE_MONOTONIC 346#if EV_USE_MONOTONIC
329 if (expect_true (have_monotonic)) 347 if (expect_true (have_monotonic))
330 { 348 {
373#define array_free(stem, idx) \ 391#define array_free(stem, idx) \
374 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 392 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
375 393
376/*****************************************************************************/ 394/*****************************************************************************/
377 395
378static void 396void noinline
379anfds_init (ANFD *base, int count)
380{
381 while (count--)
382 {
383 base->head = 0;
384 base->events = EV_NONE;
385 base->reify = 0;
386
387 ++base;
388 }
389}
390
391void
392ev_feed_event (EV_P_ void *w, int revents) 397ev_feed_event (EV_P_ void *w, int revents)
393{ 398{
394 W w_ = (W)w; 399 W w_ = (W)w;
395 400
396 if (expect_false (w_->pending)) 401 if (expect_false (w_->pending))
403 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); 408 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
404 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 409 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
405 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 410 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
406} 411}
407 412
408static void 413void inline_size
409queue_events (EV_P_ W *events, int eventcnt, int type) 414queue_events (EV_P_ W *events, int eventcnt, int type)
410{ 415{
411 int i; 416 int i;
412 417
413 for (i = 0; i < eventcnt; ++i) 418 for (i = 0; i < eventcnt; ++i)
414 ev_feed_event (EV_A_ events [i], type); 419 ev_feed_event (EV_A_ events [i], type);
415} 420}
416 421
417inline void 422/*****************************************************************************/
423
424void inline_size
425anfds_init (ANFD *base, int count)
426{
427 while (count--)
428 {
429 base->head = 0;
430 base->events = EV_NONE;
431 base->reify = 0;
432
433 ++base;
434 }
435}
436
437void inline_speed
418fd_event (EV_P_ int fd, int revents) 438fd_event (EV_P_ int fd, int revents)
419{ 439{
420 ANFD *anfd = anfds + fd; 440 ANFD *anfd = anfds + fd;
421 ev_io *w; 441 ev_io *w;
422 442
433ev_feed_fd_event (EV_P_ int fd, int revents) 453ev_feed_fd_event (EV_P_ int fd, int revents)
434{ 454{
435 fd_event (EV_A_ fd, revents); 455 fd_event (EV_A_ fd, revents);
436} 456}
437 457
438/*****************************************************************************/ 458void inline_size
439
440inline void
441fd_reify (EV_P) 459fd_reify (EV_P)
442{ 460{
443 int i; 461 int i;
444 462
445 for (i = 0; i < fdchangecnt; ++i) 463 for (i = 0; i < fdchangecnt; ++i)
469 } 487 }
470 488
471 fdchangecnt = 0; 489 fdchangecnt = 0;
472} 490}
473 491
474static void 492void inline_size
475fd_change (EV_P_ int fd) 493fd_change (EV_P_ int fd)
476{ 494{
477 if (expect_false (anfds [fd].reify)) 495 if (expect_false (anfds [fd].reify))
478 return; 496 return;
479 497
482 ++fdchangecnt; 500 ++fdchangecnt;
483 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 501 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
484 fdchanges [fdchangecnt - 1] = fd; 502 fdchanges [fdchangecnt - 1] = fd;
485} 503}
486 504
487static void 505void inline_speed
488fd_kill (EV_P_ int fd) 506fd_kill (EV_P_ int fd)
489{ 507{
490 ev_io *w; 508 ev_io *w;
491 509
492 while ((w = (ev_io *)anfds [fd].head)) 510 while ((w = (ev_io *)anfds [fd].head))
494 ev_io_stop (EV_A_ w); 512 ev_io_stop (EV_A_ w);
495 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 513 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
496 } 514 }
497} 515}
498 516
499inline int 517int inline_size
500fd_valid (int fd) 518fd_valid (int fd)
501{ 519{
502#ifdef _WIN32 520#ifdef _WIN32
503 return _get_osfhandle (fd) != -1; 521 return _get_osfhandle (fd) != -1;
504#else 522#else
505 return fcntl (fd, F_GETFD) != -1; 523 return fcntl (fd, F_GETFD) != -1;
506#endif 524#endif
507} 525}
508 526
509/* called on EBADF to verify fds */ 527/* called on EBADF to verify fds */
510static void 528static void noinline
511fd_ebadf (EV_P) 529fd_ebadf (EV_P)
512{ 530{
513 int fd; 531 int fd;
514 532
515 for (fd = 0; fd < anfdmax; ++fd) 533 for (fd = 0; fd < anfdmax; ++fd)
517 if (!fd_valid (fd) == -1 && errno == EBADF) 535 if (!fd_valid (fd) == -1 && errno == EBADF)
518 fd_kill (EV_A_ fd); 536 fd_kill (EV_A_ fd);
519} 537}
520 538
521/* called on ENOMEM in select/poll to kill some fds and retry */ 539/* called on ENOMEM in select/poll to kill some fds and retry */
522static void 540static void noinline
523fd_enomem (EV_P) 541fd_enomem (EV_P)
524{ 542{
525 int fd; 543 int fd;
526 544
527 for (fd = anfdmax; fd--; ) 545 for (fd = anfdmax; fd--; )
531 return; 549 return;
532 } 550 }
533} 551}
534 552
535/* usually called after fork if backend needs to re-arm all fds from scratch */ 553/* usually called after fork if backend needs to re-arm all fds from scratch */
536static void 554static void noinline
537fd_rearm_all (EV_P) 555fd_rearm_all (EV_P)
538{ 556{
539 int fd; 557 int fd;
540 558
541 /* this should be highly optimised to not do anything but set a flag */ 559 /* this should be highly optimised to not do anything but set a flag */
547 } 565 }
548} 566}
549 567
550/*****************************************************************************/ 568/*****************************************************************************/
551 569
552static void 570void inline_speed
553upheap (WT *heap, int k) 571upheap (WT *heap, int k)
554{ 572{
555 WT w = heap [k]; 573 WT w = heap [k];
556 574
557 while (k && heap [k >> 1]->at > w->at) 575 while (k && heap [k >> 1]->at > w->at)
564 heap [k] = w; 582 heap [k] = w;
565 ((W)heap [k])->active = k + 1; 583 ((W)heap [k])->active = k + 1;
566 584
567} 585}
568 586
569static void 587void inline_speed
570downheap (WT *heap, int N, int k) 588downheap (WT *heap, int N, int k)
571{ 589{
572 WT w = heap [k]; 590 WT w = heap [k];
573 591
574 while (k < (N >> 1)) 592 while (k < (N >> 1))
588 606
589 heap [k] = w; 607 heap [k] = w;
590 ((W)heap [k])->active = k + 1; 608 ((W)heap [k])->active = k + 1;
591} 609}
592 610
593inline void 611void inline_size
594adjustheap (WT *heap, int N, int k) 612adjustheap (WT *heap, int N, int k)
595{ 613{
596 upheap (heap, k); 614 upheap (heap, k);
597 downheap (heap, N, k); 615 downheap (heap, N, k);
598} 616}
610 628
611static int sigpipe [2]; 629static int sigpipe [2];
612static sig_atomic_t volatile gotsig; 630static sig_atomic_t volatile gotsig;
613static ev_io sigev; 631static ev_io sigev;
614 632
615static void 633void inline_size
616signals_init (ANSIG *base, int count) 634signals_init (ANSIG *base, int count)
617{ 635{
618 while (count--) 636 while (count--)
619 { 637 {
620 base->head = 0; 638 base->head = 0;
640 write (sigpipe [1], &signum, 1); 658 write (sigpipe [1], &signum, 1);
641 errno = old_errno; 659 errno = old_errno;
642 } 660 }
643} 661}
644 662
645void 663void noinline
646ev_feed_signal_event (EV_P_ int signum) 664ev_feed_signal_event (EV_P_ int signum)
647{ 665{
648 WL w; 666 WL w;
649 667
650#if EV_MULTIPLICITY 668#if EV_MULTIPLICITY
673 for (signum = signalmax; signum--; ) 691 for (signum = signalmax; signum--; )
674 if (signals [signum].gotsig) 692 if (signals [signum].gotsig)
675 ev_feed_signal_event (EV_A_ signum + 1); 693 ev_feed_signal_event (EV_A_ signum + 1);
676} 694}
677 695
678static void 696void inline_size
679fd_intern (int fd) 697fd_intern (int fd)
680{ 698{
681#ifdef _WIN32 699#ifdef _WIN32
682 int arg = 1; 700 int arg = 1;
683 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 701 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
685 fcntl (fd, F_SETFD, FD_CLOEXEC); 703 fcntl (fd, F_SETFD, FD_CLOEXEC);
686 fcntl (fd, F_SETFL, O_NONBLOCK); 704 fcntl (fd, F_SETFL, O_NONBLOCK);
687#endif 705#endif
688} 706}
689 707
690static void 708static void noinline
691siginit (EV_P) 709siginit (EV_P)
692{ 710{
693 fd_intern (sigpipe [0]); 711 fd_intern (sigpipe [0]);
694 fd_intern (sigpipe [1]); 712 fd_intern (sigpipe [1]);
695 713
698 ev_unref (EV_A); /* child watcher should not keep loop alive */ 716 ev_unref (EV_A); /* child watcher should not keep loop alive */
699} 717}
700 718
701/*****************************************************************************/ 719/*****************************************************************************/
702 720
703static ev_child *childs [PID_HASHSIZE]; 721static ev_child *childs [EV_PID_HASHSIZE];
704 722
705#ifndef _WIN32 723#ifndef _WIN32
706 724
707static ev_signal childev; 725static ev_signal childev;
708 726
709#ifndef WCONTINUED 727void inline_speed
710# define WCONTINUED 0
711#endif
712
713static void
714child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 728child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
715{ 729{
716 ev_child *w; 730 ev_child *w;
717 731
718 for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 732 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
719 if (w->pid == pid || !w->pid) 733 if (w->pid == pid || !w->pid)
720 { 734 {
721 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 735 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
722 w->rpid = pid; 736 w->rpid = pid;
723 w->rstatus = status; 737 w->rstatus = status;
724 ev_feed_event (EV_A_ (W)w, EV_CHILD); 738 ev_feed_event (EV_A_ (W)w, EV_CHILD);
725 } 739 }
726} 740}
727 741
742#ifndef WCONTINUED
743# define WCONTINUED 0
744#endif
745
728static void 746static void
729childcb (EV_P_ ev_signal *sw, int revents) 747childcb (EV_P_ ev_signal *sw, int revents)
730{ 748{
731 int pid, status; 749 int pid, status;
732 750
751 /* some systems define WCONTINUED but then fail to support it (linux 2.4) */
733 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 752 if (0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
734 { 753 if (!WCONTINUED
754 || errno != EINVAL
755 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
756 return;
757
735 /* make sure we are called again until all childs have been reaped */ 758 /* make sure we are called again until all childs have been reaped */
736 /* we need to do it this way so that the callback gets called before we continue */ 759 /* we need to do it this way so that the callback gets called before we continue */
737 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 760 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
738 761
739 child_reap (EV_A_ sw, pid, pid, status); 762 child_reap (EV_A_ sw, pid, pid, status);
763 if (EV_PID_HASHSIZE > 1)
740 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ 764 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
741 }
742} 765}
743 766
744#endif 767#endif
745 768
746/*****************************************************************************/ 769/*****************************************************************************/
772{ 795{
773 return EV_VERSION_MINOR; 796 return EV_VERSION_MINOR;
774} 797}
775 798
776/* return true if we are running with elevated privileges and should ignore env variables */ 799/* return true if we are running with elevated privileges and should ignore env variables */
777static int 800int inline_size
778enable_secure (void) 801enable_secure (void)
779{ 802{
780#ifdef _WIN32 803#ifdef _WIN32
781 return 0; 804 return 0;
782#else 805#else
829ev_backend (EV_P) 852ev_backend (EV_P)
830{ 853{
831 return backend; 854 return backend;
832} 855}
833 856
834static void 857static void noinline
835loop_init (EV_P_ unsigned int flags) 858loop_init (EV_P_ unsigned int flags)
836{ 859{
837 if (!backend) 860 if (!backend)
838 { 861 {
839#if EV_USE_MONOTONIC 862#if EV_USE_MONOTONIC
877 ev_init (&sigev, sigcb); 900 ev_init (&sigev, sigcb);
878 ev_set_priority (&sigev, EV_MAXPRI); 901 ev_set_priority (&sigev, EV_MAXPRI);
879 } 902 }
880} 903}
881 904
882static void 905static void noinline
883loop_destroy (EV_P) 906loop_destroy (EV_P)
884{ 907{
885 int i; 908 int i;
886 909
887#if EV_USE_PORT 910#if EV_USE_PORT
904 array_free (pending, [i]); 927 array_free (pending, [i]);
905 928
906 /* have to use the microsoft-never-gets-it-right macro */ 929 /* have to use the microsoft-never-gets-it-right macro */
907 array_free (fdchange, EMPTY0); 930 array_free (fdchange, EMPTY0);
908 array_free (timer, EMPTY0); 931 array_free (timer, EMPTY0);
909#if EV_PERIODICS 932#if EV_PERIODIC_ENABLE
910 array_free (periodic, EMPTY0); 933 array_free (periodic, EMPTY0);
911#endif 934#endif
912 array_free (idle, EMPTY0); 935 array_free (idle, EMPTY0);
913 array_free (prepare, EMPTY0); 936 array_free (prepare, EMPTY0);
914 array_free (check, EMPTY0); 937 array_free (check, EMPTY0);
915 938
916 backend = 0; 939 backend = 0;
917} 940}
918 941
919static void 942void inline_size
920loop_fork (EV_P) 943loop_fork (EV_P)
921{ 944{
922#if EV_USE_PORT 945#if EV_USE_PORT
923 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 946 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
924#endif 947#endif
1050 postfork = 1; 1073 postfork = 1;
1051} 1074}
1052 1075
1053/*****************************************************************************/ 1076/*****************************************************************************/
1054 1077
1055static int 1078int inline_size
1056any_pending (EV_P) 1079any_pending (EV_P)
1057{ 1080{
1058 int pri; 1081 int pri;
1059 1082
1060 for (pri = NUMPRI; pri--; ) 1083 for (pri = NUMPRI; pri--; )
1062 return 1; 1085 return 1;
1063 1086
1064 return 0; 1087 return 0;
1065} 1088}
1066 1089
1067inline void 1090void inline_speed
1068call_pending (EV_P) 1091call_pending (EV_P)
1069{ 1092{
1070 int pri; 1093 int pri;
1071 1094
1072 for (pri = NUMPRI; pri--; ) 1095 for (pri = NUMPRI; pri--; )
1074 { 1097 {
1075 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1098 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
1076 1099
1077 if (expect_true (p->w)) 1100 if (expect_true (p->w))
1078 { 1101 {
1079 assert (("non-pending watcher on pending list", p->w->pending)); 1102 /*assert (("non-pending watcher on pending list", p->w->pending));*/
1080 1103
1081 p->w->pending = 0; 1104 p->w->pending = 0;
1082 EV_CB_INVOKE (p->w, p->events); 1105 EV_CB_INVOKE (p->w, p->events);
1083 } 1106 }
1084 } 1107 }
1085} 1108}
1086 1109
1087inline void 1110void inline_size
1088timers_reify (EV_P) 1111timers_reify (EV_P)
1089{ 1112{
1090 while (timercnt && ((WT)timers [0])->at <= mn_now) 1113 while (timercnt && ((WT)timers [0])->at <= mn_now)
1091 { 1114 {
1092 ev_timer *w = timers [0]; 1115 ev_timer *w = timers [0];
1093 1116
1094 assert (("inactive timer on timer heap detected", ev_is_active (w))); 1117 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1095 1118
1096 /* first reschedule or stop timer */ 1119 /* first reschedule or stop timer */
1097 if (w->repeat) 1120 if (w->repeat)
1098 { 1121 {
1099 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 1122 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1109 1132
1110 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1133 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1111 } 1134 }
1112} 1135}
1113 1136
1114#if EV_PERIODICS 1137#if EV_PERIODIC_ENABLE
1115inline void 1138void inline_size
1116periodics_reify (EV_P) 1139periodics_reify (EV_P)
1117{ 1140{
1118 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1141 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1119 { 1142 {
1120 ev_periodic *w = periodics [0]; 1143 ev_periodic *w = periodics [0];
1121 1144
1122 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1145 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1123 1146
1124 /* first reschedule or stop timer */ 1147 /* first reschedule or stop timer */
1125 if (w->reschedule_cb) 1148 if (w->reschedule_cb)
1126 { 1149 {
1127 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); 1150 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001);
1139 1162
1140 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1163 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1141 } 1164 }
1142} 1165}
1143 1166
1144static void 1167static void noinline
1145periodics_reschedule (EV_P) 1168periodics_reschedule (EV_P)
1146{ 1169{
1147 int i; 1170 int i;
1148 1171
1149 /* adjust periodics after time jump */ 1172 /* adjust periodics after time jump */
1161 for (i = periodiccnt >> 1; i--; ) 1184 for (i = periodiccnt >> 1; i--; )
1162 downheap ((WT *)periodics, periodiccnt, i); 1185 downheap ((WT *)periodics, periodiccnt, i);
1163} 1186}
1164#endif 1187#endif
1165 1188
1166inline int 1189int inline_size
1167time_update_monotonic (EV_P) 1190time_update_monotonic (EV_P)
1168{ 1191{
1169 mn_now = get_clock (); 1192 mn_now = get_clock ();
1170 1193
1171 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 1194 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
1179 ev_rt_now = ev_time (); 1202 ev_rt_now = ev_time ();
1180 return 1; 1203 return 1;
1181 } 1204 }
1182} 1205}
1183 1206
1184inline void 1207void inline_size
1185time_update (EV_P) 1208time_update (EV_P)
1186{ 1209{
1187 int i; 1210 int i;
1188 1211
1189#if EV_USE_MONOTONIC 1212#if EV_USE_MONOTONIC
1211 ev_rt_now = ev_time (); 1234 ev_rt_now = ev_time ();
1212 mn_now = get_clock (); 1235 mn_now = get_clock ();
1213 now_floor = mn_now; 1236 now_floor = mn_now;
1214 } 1237 }
1215 1238
1216# if EV_PERIODICS 1239# if EV_PERIODIC_ENABLE
1217 periodics_reschedule (EV_A); 1240 periodics_reschedule (EV_A);
1218# endif 1241# endif
1219 /* no timer adjustment, as the monotonic clock doesn't jump */ 1242 /* no timer adjustment, as the monotonic clock doesn't jump */
1220 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ 1243 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1221 } 1244 }
1225 { 1248 {
1226 ev_rt_now = ev_time (); 1249 ev_rt_now = ev_time ();
1227 1250
1228 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1251 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
1229 { 1252 {
1230#if EV_PERIODICS 1253#if EV_PERIODIC_ENABLE
1231 periodics_reschedule (EV_A); 1254 periodics_reschedule (EV_A);
1232#endif 1255#endif
1233 1256
1234 /* adjust timers. this is easy, as the offset is the same for all */ 1257 /* adjust timers. this is easy, as the offset is the same for all */
1235 for (i = 0; i < timercnt; ++i) 1258 for (i = 0; i < timercnt; ++i)
1261 ? EVUNLOOP_ONE 1284 ? EVUNLOOP_ONE
1262 : EVUNLOOP_CANCEL; 1285 : EVUNLOOP_CANCEL;
1263 1286
1264 while (activecnt) 1287 while (activecnt)
1265 { 1288 {
1289 /* we might have forked, so reify kernel state if necessary */
1290 #if EV_FORK_ENABLE
1291 if (expect_false (postfork))
1292 if (forkcnt)
1293 {
1294 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1295 call_pending (EV_A);
1296 }
1297 #endif
1298
1266 /* queue check watchers (and execute them) */ 1299 /* queue check watchers (and execute them) */
1267 if (expect_false (preparecnt)) 1300 if (expect_false (preparecnt))
1268 { 1301 {
1269 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1302 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1270 call_pending (EV_A); 1303 call_pending (EV_A);
1302 { 1335 {
1303 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1336 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1304 if (block > to) block = to; 1337 if (block > to) block = to;
1305 } 1338 }
1306 1339
1307#if EV_PERIODICS 1340#if EV_PERIODIC_ENABLE
1308 if (periodiccnt) 1341 if (periodiccnt)
1309 { 1342 {
1310 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1343 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge;
1311 if (block > to) block = to; 1344 if (block > to) block = to;
1312 } 1345 }
1321 /* update ev_rt_now, do magic */ 1354 /* update ev_rt_now, do magic */
1322 time_update (EV_A); 1355 time_update (EV_A);
1323 1356
1324 /* queue pending timers and reschedule them */ 1357 /* queue pending timers and reschedule them */
1325 timers_reify (EV_A); /* relative timers called last */ 1358 timers_reify (EV_A); /* relative timers called last */
1326#if EV_PERIODICS 1359#if EV_PERIODIC_ENABLE
1327 periodics_reify (EV_A); /* absolute timers called first */ 1360 periodics_reify (EV_A); /* absolute timers called first */
1328#endif 1361#endif
1329 1362
1330 /* queue idle watchers unless other events are pending */ 1363 /* queue idle watchers unless other events are pending */
1331 if (idlecnt && !any_pending (EV_A)) 1364 if (idlecnt && !any_pending (EV_A))
1351 loop_done = how; 1384 loop_done = how;
1352} 1385}
1353 1386
1354/*****************************************************************************/ 1387/*****************************************************************************/
1355 1388
1356inline void 1389void inline_size
1357wlist_add (WL *head, WL elem) 1390wlist_add (WL *head, WL elem)
1358{ 1391{
1359 elem->next = *head; 1392 elem->next = *head;
1360 *head = elem; 1393 *head = elem;
1361} 1394}
1362 1395
1363inline void 1396void inline_size
1364wlist_del (WL *head, WL elem) 1397wlist_del (WL *head, WL elem)
1365{ 1398{
1366 while (*head) 1399 while (*head)
1367 { 1400 {
1368 if (*head == elem) 1401 if (*head == elem)
1373 1406
1374 head = &(*head)->next; 1407 head = &(*head)->next;
1375 } 1408 }
1376} 1409}
1377 1410
1378inline void 1411void inline_speed
1379ev_clear_pending (EV_P_ W w) 1412ev_clear_pending (EV_P_ W w)
1380{ 1413{
1381 if (w->pending) 1414 if (w->pending)
1382 { 1415 {
1383 pendings [ABSPRI (w)][w->pending - 1].w = 0; 1416 pendings [ABSPRI (w)][w->pending - 1].w = 0;
1384 w->pending = 0; 1417 w->pending = 0;
1385 } 1418 }
1386} 1419}
1387 1420
1388inline void 1421void inline_speed
1389ev_start (EV_P_ W w, int active) 1422ev_start (EV_P_ W w, int active)
1390{ 1423{
1391 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; 1424 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI;
1392 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; 1425 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
1393 1426
1394 w->active = active; 1427 w->active = active;
1395 ev_ref (EV_A); 1428 ev_ref (EV_A);
1396} 1429}
1397 1430
1398inline void 1431void inline_size
1399ev_stop (EV_P_ W w) 1432ev_stop (EV_P_ W w)
1400{ 1433{
1401 ev_unref (EV_A); 1434 ev_unref (EV_A);
1402 w->active = 0; 1435 w->active = 0;
1403} 1436}
1449 ev_start (EV_A_ (W)w, ++timercnt); 1482 ev_start (EV_A_ (W)w, ++timercnt);
1450 array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2); 1483 array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2);
1451 timers [timercnt - 1] = w; 1484 timers [timercnt - 1] = w;
1452 upheap ((WT *)timers, timercnt - 1); 1485 upheap ((WT *)timers, timercnt - 1);
1453 1486
1454 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1487 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/
1455} 1488}
1456 1489
1457void 1490void
1458ev_timer_stop (EV_P_ ev_timer *w) 1491ev_timer_stop (EV_P_ ev_timer *w)
1459{ 1492{
1461 if (expect_false (!ev_is_active (w))) 1494 if (expect_false (!ev_is_active (w)))
1462 return; 1495 return;
1463 1496
1464 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1497 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1465 1498
1499 {
1500 int active = ((W)w)->active;
1501
1466 if (expect_true (((W)w)->active < timercnt--)) 1502 if (expect_true (--active < --timercnt))
1467 { 1503 {
1468 timers [((W)w)->active - 1] = timers [timercnt]; 1504 timers [active] = timers [timercnt];
1469 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1505 adjustheap ((WT *)timers, timercnt, active);
1470 } 1506 }
1507 }
1471 1508
1472 ((WT)w)->at -= mn_now; 1509 ((WT)w)->at -= mn_now;
1473 1510
1474 ev_stop (EV_A_ (W)w); 1511 ev_stop (EV_A_ (W)w);
1475} 1512}
1492 w->at = w->repeat; 1529 w->at = w->repeat;
1493 ev_timer_start (EV_A_ w); 1530 ev_timer_start (EV_A_ w);
1494 } 1531 }
1495} 1532}
1496 1533
1497#if EV_PERIODICS 1534#if EV_PERIODIC_ENABLE
1498void 1535void
1499ev_periodic_start (EV_P_ ev_periodic *w) 1536ev_periodic_start (EV_P_ ev_periodic *w)
1500{ 1537{
1501 if (expect_false (ev_is_active (w))) 1538 if (expect_false (ev_is_active (w)))
1502 return; 1539 return;
1513 ev_start (EV_A_ (W)w, ++periodiccnt); 1550 ev_start (EV_A_ (W)w, ++periodiccnt);
1514 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); 1551 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
1515 periodics [periodiccnt - 1] = w; 1552 periodics [periodiccnt - 1] = w;
1516 upheap ((WT *)periodics, periodiccnt - 1); 1553 upheap ((WT *)periodics, periodiccnt - 1);
1517 1554
1518 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1555 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/
1519} 1556}
1520 1557
1521void 1558void
1522ev_periodic_stop (EV_P_ ev_periodic *w) 1559ev_periodic_stop (EV_P_ ev_periodic *w)
1523{ 1560{
1525 if (expect_false (!ev_is_active (w))) 1562 if (expect_false (!ev_is_active (w)))
1526 return; 1563 return;
1527 1564
1528 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1565 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1529 1566
1567 {
1568 int active = ((W)w)->active;
1569
1530 if (expect_true (((W)w)->active < periodiccnt--)) 1570 if (expect_true (--active < --periodiccnt))
1531 { 1571 {
1532 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1572 periodics [active] = periodics [periodiccnt];
1533 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1573 adjustheap ((WT *)periodics, periodiccnt, active);
1534 } 1574 }
1575 }
1535 1576
1536 ev_stop (EV_A_ (W)w); 1577 ev_stop (EV_A_ (W)w);
1537} 1578}
1538 1579
1539void 1580void
1542 /* TODO: use adjustheap and recalculation */ 1583 /* TODO: use adjustheap and recalculation */
1543 ev_periodic_stop (EV_A_ w); 1584 ev_periodic_stop (EV_A_ w);
1544 ev_periodic_start (EV_A_ w); 1585 ev_periodic_start (EV_A_ w);
1545} 1586}
1546#endif 1587#endif
1547
1548void
1549ev_idle_start (EV_P_ ev_idle *w)
1550{
1551 if (expect_false (ev_is_active (w)))
1552 return;
1553
1554 ev_start (EV_A_ (W)w, ++idlecnt);
1555 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1556 idles [idlecnt - 1] = w;
1557}
1558
1559void
1560ev_idle_stop (EV_P_ ev_idle *w)
1561{
1562 ev_clear_pending (EV_A_ (W)w);
1563 if (expect_false (!ev_is_active (w)))
1564 return;
1565
1566 {
1567 int active = ((W)w)->active;
1568 idles [active - 1] = idles [--idlecnt];
1569 ((W)idles [active - 1])->active = active;
1570 }
1571
1572 ev_stop (EV_A_ (W)w);
1573}
1574
1575void
1576ev_prepare_start (EV_P_ ev_prepare *w)
1577{
1578 if (expect_false (ev_is_active (w)))
1579 return;
1580
1581 ev_start (EV_A_ (W)w, ++preparecnt);
1582 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1583 prepares [preparecnt - 1] = w;
1584}
1585
1586void
1587ev_prepare_stop (EV_P_ ev_prepare *w)
1588{
1589 ev_clear_pending (EV_A_ (W)w);
1590 if (expect_false (!ev_is_active (w)))
1591 return;
1592
1593 {
1594 int active = ((W)w)->active;
1595 prepares [active - 1] = prepares [--preparecnt];
1596 ((W)prepares [active - 1])->active = active;
1597 }
1598
1599 ev_stop (EV_A_ (W)w);
1600}
1601
1602void
1603ev_check_start (EV_P_ ev_check *w)
1604{
1605 if (expect_false (ev_is_active (w)))
1606 return;
1607
1608 ev_start (EV_A_ (W)w, ++checkcnt);
1609 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1610 checks [checkcnt - 1] = w;
1611}
1612
1613void
1614ev_check_stop (EV_P_ ev_check *w)
1615{
1616 ev_clear_pending (EV_A_ (W)w);
1617 if (expect_false (!ev_is_active (w)))
1618 return;
1619
1620 {
1621 int active = ((W)w)->active;
1622 checks [active - 1] = checks [--checkcnt];
1623 ((W)checks [active - 1])->active = active;
1624 }
1625
1626 ev_stop (EV_A_ (W)w);
1627}
1628 1588
1629#ifndef SA_RESTART 1589#ifndef SA_RESTART
1630# define SA_RESTART 0 1590# define SA_RESTART 0
1631#endif 1591#endif
1632 1592
1681#endif 1641#endif
1682 if (expect_false (ev_is_active (w))) 1642 if (expect_false (ev_is_active (w)))
1683 return; 1643 return;
1684 1644
1685 ev_start (EV_A_ (W)w, 1); 1645 ev_start (EV_A_ (W)w, 1);
1686 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1646 wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1687} 1647}
1688 1648
1689void 1649void
1690ev_child_stop (EV_P_ ev_child *w) 1650ev_child_stop (EV_P_ ev_child *w)
1691{ 1651{
1692 ev_clear_pending (EV_A_ (W)w); 1652 ev_clear_pending (EV_A_ (W)w);
1693 if (expect_false (!ev_is_active (w))) 1653 if (expect_false (!ev_is_active (w)))
1694 return; 1654 return;
1695 1655
1696 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1656 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1697 ev_stop (EV_A_ (W)w); 1657 ev_stop (EV_A_ (W)w);
1698} 1658}
1699 1659
1700#if EV_MULTIPLICITY 1660#if EV_STAT_ENABLE
1661
1662# ifdef _WIN32
1663# undef lstat
1664# define lstat(a,b) _stati64 (a,b)
1665# endif
1666
1667#define DEF_STAT_INTERVAL 5.0074891
1668#define MIN_STAT_INTERVAL 0.1074891
1669
1701void 1670void
1671ev_stat_stat (EV_P_ ev_stat *w)
1672{
1673 if (lstat (w->path, &w->attr) < 0)
1674 w->attr.st_nlink = 0;
1675 else if (!w->attr.st_nlink)
1676 w->attr.st_nlink = 1;
1677}
1678
1679static void
1680stat_timer_cb (EV_P_ ev_timer *w_, int revents)
1681{
1682 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
1683
1684 /* we copy this here each the time so that */
1685 /* prev has the old value when the callback gets invoked */
1686 w->prev = w->attr;
1687 ev_stat_stat (EV_A_ w);
1688
1689 if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata)))
1690 ev_feed_event (EV_A_ w, EV_STAT);
1691}
1692
1693void
1694ev_stat_start (EV_P_ ev_stat *w)
1695{
1696 if (expect_false (ev_is_active (w)))
1697 return;
1698
1699 /* since we use memcmp, we need to clear any padding data etc. */
1700 memset (&w->prev, 0, sizeof (ev_statdata));
1701 memset (&w->attr, 0, sizeof (ev_statdata));
1702
1703 ev_stat_stat (EV_A_ w);
1704
1705 if (w->interval < MIN_STAT_INTERVAL)
1706 w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL;
1707
1708 ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval);
1709 ev_set_priority (&w->timer, ev_priority (w));
1710 ev_timer_start (EV_A_ &w->timer);
1711
1712 ev_start (EV_A_ (W)w, 1);
1713}
1714
1715void
1716ev_stat_stop (EV_P_ ev_stat *w)
1717{
1718 ev_clear_pending (EV_A_ (W)w);
1719 if (expect_false (!ev_is_active (w)))
1720 return;
1721
1722 ev_timer_stop (EV_A_ &w->timer);
1723
1724 ev_stop (EV_A_ (W)w);
1725}
1726#endif
1727
1728void
1729ev_idle_start (EV_P_ ev_idle *w)
1730{
1731 if (expect_false (ev_is_active (w)))
1732 return;
1733
1734 ev_start (EV_A_ (W)w, ++idlecnt);
1735 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1736 idles [idlecnt - 1] = w;
1737}
1738
1739void
1740ev_idle_stop (EV_P_ ev_idle *w)
1741{
1742 ev_clear_pending (EV_A_ (W)w);
1743 if (expect_false (!ev_is_active (w)))
1744 return;
1745
1746 {
1747 int active = ((W)w)->active;
1748 idles [active - 1] = idles [--idlecnt];
1749 ((W)idles [active - 1])->active = active;
1750 }
1751
1752 ev_stop (EV_A_ (W)w);
1753}
1754
1755void
1756ev_prepare_start (EV_P_ ev_prepare *w)
1757{
1758 if (expect_false (ev_is_active (w)))
1759 return;
1760
1761 ev_start (EV_A_ (W)w, ++preparecnt);
1762 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1763 prepares [preparecnt - 1] = w;
1764}
1765
1766void
1767ev_prepare_stop (EV_P_ ev_prepare *w)
1768{
1769 ev_clear_pending (EV_A_ (W)w);
1770 if (expect_false (!ev_is_active (w)))
1771 return;
1772
1773 {
1774 int active = ((W)w)->active;
1775 prepares [active - 1] = prepares [--preparecnt];
1776 ((W)prepares [active - 1])->active = active;
1777 }
1778
1779 ev_stop (EV_A_ (W)w);
1780}
1781
1782void
1783ev_check_start (EV_P_ ev_check *w)
1784{
1785 if (expect_false (ev_is_active (w)))
1786 return;
1787
1788 ev_start (EV_A_ (W)w, ++checkcnt);
1789 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1790 checks [checkcnt - 1] = w;
1791}
1792
1793void
1794ev_check_stop (EV_P_ ev_check *w)
1795{
1796 ev_clear_pending (EV_A_ (W)w);
1797 if (expect_false (!ev_is_active (w)))
1798 return;
1799
1800 {
1801 int active = ((W)w)->active;
1802 checks [active - 1] = checks [--checkcnt];
1803 ((W)checks [active - 1])->active = active;
1804 }
1805
1806 ev_stop (EV_A_ (W)w);
1807}
1808
1809#if EV_EMBED_ENABLE
1810void noinline
1702ev_embed_sweep (EV_P_ ev_embed *w) 1811ev_embed_sweep (EV_P_ ev_embed *w)
1703{ 1812{
1704 ev_loop (w->loop, EVLOOP_NONBLOCK); 1813 ev_loop (w->loop, EVLOOP_NONBLOCK);
1705} 1814}
1706 1815
1727 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); 1836 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
1728 } 1837 }
1729 1838
1730 ev_set_priority (&w->io, ev_priority (w)); 1839 ev_set_priority (&w->io, ev_priority (w));
1731 ev_io_start (EV_A_ &w->io); 1840 ev_io_start (EV_A_ &w->io);
1841
1732 ev_start (EV_A_ (W)w, 1); 1842 ev_start (EV_A_ (W)w, 1);
1733} 1843}
1734 1844
1735void 1845void
1736ev_embed_stop (EV_P_ ev_embed *w) 1846ev_embed_stop (EV_P_ ev_embed *w)
1738 ev_clear_pending (EV_A_ (W)w); 1848 ev_clear_pending (EV_A_ (W)w);
1739 if (expect_false (!ev_is_active (w))) 1849 if (expect_false (!ev_is_active (w)))
1740 return; 1850 return;
1741 1851
1742 ev_io_stop (EV_A_ &w->io); 1852 ev_io_stop (EV_A_ &w->io);
1853
1854 ev_stop (EV_A_ (W)w);
1855}
1856#endif
1857
1858#if EV_FORK_ENABLE
1859void
1860ev_fork_start (EV_P_ ev_fork *w)
1861{
1862 if (expect_false (ev_is_active (w)))
1863 return;
1864
1865 ev_start (EV_A_ (W)w, ++forkcnt);
1866 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2);
1867 forks [forkcnt - 1] = w;
1868}
1869
1870void
1871ev_fork_stop (EV_P_ ev_fork *w)
1872{
1873 ev_clear_pending (EV_A_ (W)w);
1874 if (expect_false (!ev_is_active (w)))
1875 return;
1876
1877 {
1878 int active = ((W)w)->active;
1879 forks [active - 1] = forks [--forkcnt];
1880 ((W)forks [active - 1])->active = active;
1881 }
1882
1743 ev_stop (EV_A_ (W)w); 1883 ev_stop (EV_A_ (W)w);
1744} 1884}
1745#endif 1885#endif
1746 1886
1747/*****************************************************************************/ 1887/*****************************************************************************/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines