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

Comparing libev/ev.c (file contents):
Revision 1.97 by root, Sun Nov 11 01:53:07 2007 UTC vs.
Revision 1.110 by root, Mon Nov 12 05:56:49 2007 UTC

51 51
52# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) 52# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL)
53# define EV_USE_POLL 1 53# define EV_USE_POLL 1
54# endif 54# endif
55 55
56# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) 56# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL)
57# define EV_USE_EPOLL 1 57# define EV_USE_EPOLL 1
58# endif 58# endif
59 59
60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) 60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE)
61# define EV_USE_KQUEUE 1 61# define EV_USE_KQUEUE 1
75#include <sys/types.h> 75#include <sys/types.h>
76#include <time.h> 76#include <time.h>
77 77
78#include <signal.h> 78#include <signal.h>
79 79
80#ifndef WIN32 80#ifndef _WIN32
81# include <unistd.h> 81# include <unistd.h>
82# include <sys/time.h> 82# include <sys/time.h>
83# 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
84#endif 89# endif
90#endif
91
85/**/ 92/**/
86 93
87#ifndef EV_USE_MONOTONIC 94#ifndef EV_USE_MONOTONIC
88# define EV_USE_MONOTONIC 1 95# define EV_USE_MONOTONIC 1
89#endif 96#endif
90 97
91#ifndef EV_USE_SELECT 98#ifndef EV_USE_SELECT
92# define EV_USE_SELECT 1 99# define EV_USE_SELECT 1
100# define EV_SELECT_USE_FD_SET 1
93#endif 101#endif
94 102
95#ifndef EV_USE_POLL 103#ifndef EV_USE_POLL
96# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ 104# ifdef _WIN32
105# define EV_USE_POLL 0
106# else
107# define EV_USE_POLL 1
108# endif
97#endif 109#endif
98 110
99#ifndef EV_USE_EPOLL 111#ifndef EV_USE_EPOLL
100# define EV_USE_EPOLL 0 112# define EV_USE_EPOLL 0
101#endif 113#endif
102 114
103#ifndef EV_USE_KQUEUE 115#ifndef EV_USE_KQUEUE
104# define EV_USE_KQUEUE 0 116# define EV_USE_KQUEUE 0
105#endif 117#endif
106 118
107#ifndef EV_USE_WIN32
108# ifdef WIN32
109# define EV_USE_WIN32 0 /* it does not exist, use select */
110# undef EV_USE_SELECT
111# define EV_USE_SELECT 1
112# else
113# define EV_USE_WIN32 0
114# endif
115#endif
116
117#ifndef EV_USE_REALTIME 119#ifndef EV_USE_REALTIME
118# define EV_USE_REALTIME 1 120# define EV_USE_REALTIME 1
119#endif 121#endif
120 122
121/**/ 123/**/
124
125/* darwin simply cannot be helped */
126#ifdef __APPLE__
127# undef EV_USE_POLL
128# undef EV_USE_KQUEUE
129#endif
122 130
123#ifndef CLOCK_MONOTONIC 131#ifndef CLOCK_MONOTONIC
124# undef EV_USE_MONOTONIC 132# undef EV_USE_MONOTONIC
125# define EV_USE_MONOTONIC 0 133# define EV_USE_MONOTONIC 0
126#endif 134#endif
127 135
128#ifndef CLOCK_REALTIME 136#ifndef CLOCK_REALTIME
129# undef EV_USE_REALTIME 137# undef EV_USE_REALTIME
130# define EV_USE_REALTIME 0 138# define EV_USE_REALTIME 0
139#endif
140
141#if EV_SELECT_IS_WINSOCKET
142# include <winsock.h>
131#endif 143#endif
132 144
133/**/ 145/**/
134 146
135#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 147#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
155#define expect_true(expr) expect ((expr) != 0, 1) 167#define expect_true(expr) expect ((expr) != 0, 1)
156 168
157#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 169#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
158#define ABSPRI(w) ((w)->priority - EV_MINPRI) 170#define ABSPRI(w) ((w)->priority - EV_MINPRI)
159 171
172#define EMPTY /* required for microsofts broken pseudo-c compiler */
173
160typedef struct ev_watcher *W; 174typedef struct ev_watcher *W;
161typedef struct ev_watcher_list *WL; 175typedef struct ev_watcher_list *WL;
162typedef struct ev_watcher_time *WT; 176typedef struct ev_watcher_time *WT;
163 177
164static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 178static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
165 179
180#ifdef _WIN32
166#include "ev_win32.c" 181# include "ev_win32.c"
182#endif
167 183
168/*****************************************************************************/ 184/*****************************************************************************/
169 185
170static void (*syserr_cb)(const char *msg); 186static void (*syserr_cb)(const char *msg);
171 187
218typedef struct 234typedef struct
219{ 235{
220 WL head; 236 WL head;
221 unsigned char events; 237 unsigned char events;
222 unsigned char reify; 238 unsigned char reify;
239#if EV_SELECT_IS_WINSOCKET
240 SOCKET handle;
241#endif
223} ANFD; 242} ANFD;
224 243
225typedef struct 244typedef struct
226{ 245{
227 W w; 246 W w;
231#if EV_MULTIPLICITY 250#if EV_MULTIPLICITY
232 251
233 struct ev_loop 252 struct ev_loop
234 { 253 {
235 ev_tstamp ev_rt_now; 254 ev_tstamp ev_rt_now;
255 #define ev_rt_now ((loop)->ev_rt_now)
236 #define VAR(name,decl) decl; 256 #define VAR(name,decl) decl;
237 #include "ev_vars.h" 257 #include "ev_vars.h"
238 #undef VAR 258 #undef VAR
239 }; 259 };
240 #include "ev_wrap.h" 260 #include "ev_wrap.h"
290{ 310{
291 return ev_rt_now; 311 return ev_rt_now;
292} 312}
293#endif 313#endif
294 314
295#define array_roundsize(type,n) ((n) | 4 & ~3) 315#define array_roundsize(type,n) (((n) | 4) & ~3)
296 316
297#define array_needsize(type,base,cur,cnt,init) \ 317#define array_needsize(type,base,cur,cnt,init) \
298 if (expect_false ((cnt) > cur)) \ 318 if (expect_false ((cnt) > cur)) \
299 { \ 319 { \
300 int newcnt = cur; \ 320 int newcnt = cur; \
315 stem ## max = array_roundsize (stem ## cnt >> 1); \ 335 stem ## max = array_roundsize (stem ## cnt >> 1); \
316 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 336 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
317 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 337 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
318 } 338 }
319 339
320/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
321/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
322#define array_free_microshit(stem) \
323 ev_free (stem ## s); stem ## cnt = stem ## max = 0;
324
325#define array_free(stem, idx) \ 340#define array_free(stem, idx) \
326 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 341 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
327 342
328/*****************************************************************************/ 343/*****************************************************************************/
329 344
403 int events = 0; 418 int events = 0;
404 419
405 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 420 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
406 events |= w->events; 421 events |= w->events;
407 422
423#if EV_SELECT_IS_WINSOCKET
424 if (events)
425 {
426 unsigned long argp;
427 anfd->handle = _get_osfhandle (fd);
428 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
429 }
430#endif
431
408 anfd->reify = 0; 432 anfd->reify = 0;
409 433
410 method_modify (EV_A_ fd, anfd->events, events); 434 method_modify (EV_A_ fd, anfd->events, events);
411 anfd->events = events; 435 anfd->events = events;
412 } 436 }
440} 464}
441 465
442static int 466static int
443fd_valid (int fd) 467fd_valid (int fd)
444{ 468{
445#ifdef WIN32 469#ifdef _WIN32
446 return !!win32_get_osfhandle (fd); 470 return _get_osfhandle (fd) != -1;
447#else 471#else
448 return fcntl (fd, F_GETFD) != -1; 472 return fcntl (fd, F_GETFD) != -1;
449#endif 473#endif
450} 474}
451 475
532 heap [k] = w; 556 heap [k] = w;
533 ((W)heap [k])->active = k + 1; 557 ((W)heap [k])->active = k + 1;
534} 558}
535 559
536inline void 560inline void
537adjustheap (WT *heap, int N, int k, ev_tstamp at) 561adjustheap (WT *heap, int N, int k)
538{ 562{
539 ev_tstamp old_at = heap [k]->at; 563 upheap (heap, k);
540 heap [k]->at = at;
541
542 if (old_at < at)
543 downheap (heap, N, k); 564 downheap (heap, N, k);
544 else
545 upheap (heap, k);
546} 565}
547 566
548/*****************************************************************************/ 567/*****************************************************************************/
549 568
550typedef struct 569typedef struct
573} 592}
574 593
575static void 594static void
576sighandler (int signum) 595sighandler (int signum)
577{ 596{
578#if WIN32 597#if _WIN32
579 signal (signum, sighandler); 598 signal (signum, sighandler);
580#endif 599#endif
581 600
582 signals [signum - 1].gotsig = 1; 601 signals [signum - 1].gotsig = 1;
583 602
584 if (!gotsig) 603 if (!gotsig)
585 { 604 {
586 int old_errno = errno; 605 int old_errno = errno;
587 gotsig = 1; 606 gotsig = 1;
588#ifdef WIN32
589 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
590#else
591 write (sigpipe [1], &signum, 1); 607 write (sigpipe [1], &signum, 1);
592#endif
593 errno = old_errno; 608 errno = old_errno;
594 } 609 }
595} 610}
596 611
597void 612void
617static void 632static void
618sigcb (EV_P_ struct ev_io *iow, int revents) 633sigcb (EV_P_ struct ev_io *iow, int revents)
619{ 634{
620 int signum; 635 int signum;
621 636
622#ifdef WIN32
623 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
624#else
625 read (sigpipe [0], &revents, 1); 637 read (sigpipe [0], &revents, 1);
626#endif
627 gotsig = 0; 638 gotsig = 0;
628 639
629 for (signum = signalmax; signum--; ) 640 for (signum = signalmax; signum--; )
630 if (signals [signum].gotsig) 641 if (signals [signum].gotsig)
631 ev_feed_signal_event (EV_A_ signum + 1); 642 ev_feed_signal_event (EV_A_ signum + 1);
632} 643}
633 644
645inline void
646fd_intern (int fd)
647{
648#ifdef _WIN32
649 int arg = 1;
650 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
651#else
652 fcntl (fd, F_SETFD, FD_CLOEXEC);
653 fcntl (fd, F_SETFL, O_NONBLOCK);
654#endif
655}
656
634static void 657static void
635siginit (EV_P) 658siginit (EV_P)
636{ 659{
637#ifndef WIN32 660 fd_intern (sigpipe [0]);
638 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); 661 fd_intern (sigpipe [1]);
639 fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
640
641 /* rather than sort out wether we really need nb, set it */
642 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
643 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
644#endif
645 662
646 ev_io_set (&sigev, sigpipe [0], EV_READ); 663 ev_io_set (&sigev, sigpipe [0], EV_READ);
647 ev_io_start (EV_A_ &sigev); 664 ev_io_start (EV_A_ &sigev);
648 ev_unref (EV_A); /* child watcher should not keep loop alive */ 665 ev_unref (EV_A); /* child watcher should not keep loop alive */
649} 666}
650 667
651/*****************************************************************************/ 668/*****************************************************************************/
652 669
653static struct ev_child *childs [PID_HASHSIZE]; 670static struct ev_child *childs [PID_HASHSIZE];
654 671
655#ifndef WIN32 672#ifndef _WIN32
656 673
657static struct ev_signal childev; 674static struct ev_signal childev;
658 675
659#ifndef WCONTINUED 676#ifndef WCONTINUED
660# define WCONTINUED 0 677# define WCONTINUED 0
721 738
722/* return true if we are running with elevated privileges and should ignore env variables */ 739/* return true if we are running with elevated privileges and should ignore env variables */
723static int 740static int
724enable_secure (void) 741enable_secure (void)
725{ 742{
726#ifdef WIN32 743#ifdef _WIN32
727 return 0; 744 return 0;
728#else 745#else
729 return getuid () != geteuid () 746 return getuid () != geteuid ()
730 || getgid () != getegid (); 747 || getgid () != getegid ();
731#endif 748#endif
736{ 753{
737 return method; 754 return method;
738} 755}
739 756
740static void 757static void
741loop_init (EV_P_ int methods) 758loop_init (EV_P_ unsigned int flags)
742{ 759{
743 if (!method) 760 if (!method)
744 { 761 {
745#if EV_USE_MONOTONIC 762#if EV_USE_MONOTONIC
746 { 763 {
753 ev_rt_now = ev_time (); 770 ev_rt_now = ev_time ();
754 mn_now = get_clock (); 771 mn_now = get_clock ();
755 now_floor = mn_now; 772 now_floor = mn_now;
756 rtmn_diff = ev_rt_now - mn_now; 773 rtmn_diff = ev_rt_now - mn_now;
757 774
758 if (methods == EVMETHOD_AUTO) 775 if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS"))
759 if (!enable_secure () && getenv ("LIBEV_METHODS"))
760 methods = atoi (getenv ("LIBEV_METHODS")); 776 flags = atoi (getenv ("LIBEV_FLAGS"));
761 else 777
762 methods = EVMETHOD_ANY; 778 if (!(flags & 0x0000ffff))
779 flags |= 0x0000ffff;
763 780
764 method = 0; 781 method = 0;
765#if EV_USE_WIN32
766 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
767#endif
768#if EV_USE_KQUEUE 782#if EV_USE_KQUEUE
769 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 783 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
770#endif 784#endif
771#if EV_USE_EPOLL 785#if EV_USE_EPOLL
772 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 786 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
773#endif 787#endif
774#if EV_USE_POLL 788#if EV_USE_POLL
775 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 789 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags);
776#endif 790#endif
777#if EV_USE_SELECT 791#if EV_USE_SELECT
778 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 792 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags);
779#endif 793#endif
780 794
781 ev_init (&sigev, sigcb); 795 ev_init (&sigev, sigcb);
782 ev_set_priority (&sigev, EV_MAXPRI); 796 ev_set_priority (&sigev, EV_MAXPRI);
783 } 797 }
786void 800void
787loop_destroy (EV_P) 801loop_destroy (EV_P)
788{ 802{
789 int i; 803 int i;
790 804
791#if EV_USE_WIN32
792 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
793#endif
794#if EV_USE_KQUEUE 805#if EV_USE_KQUEUE
795 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 806 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
796#endif 807#endif
797#if EV_USE_EPOLL 808#if EV_USE_EPOLL
798 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 809 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
806 817
807 for (i = NUMPRI; i--; ) 818 for (i = NUMPRI; i--; )
808 array_free (pending, [i]); 819 array_free (pending, [i]);
809 820
810 /* have to use the microsoft-never-gets-it-right macro */ 821 /* have to use the microsoft-never-gets-it-right macro */
811 array_free_microshit (fdchange); 822 array_free (fdchange, EMPTY);
812 array_free_microshit (timer); 823 array_free (timer, EMPTY);
813#if EV_PERIODICS 824#if EV_PERIODICS
814 array_free_microshit (periodic); 825 array_free (periodic, EMPTY);
815#endif 826#endif
816 array_free_microshit (idle); 827 array_free (idle, EMPTY);
817 array_free_microshit (prepare); 828 array_free (prepare, EMPTY);
818 array_free_microshit (check); 829 array_free (check, EMPTY);
819 830
820 method = 0; 831 method = 0;
821} 832}
822 833
823static void 834static void
848 postfork = 0; 859 postfork = 0;
849} 860}
850 861
851#if EV_MULTIPLICITY 862#if EV_MULTIPLICITY
852struct ev_loop * 863struct ev_loop *
853ev_loop_new (int methods) 864ev_loop_new (unsigned int flags)
854{ 865{
855 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 866 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
856 867
857 memset (loop, 0, sizeof (struct ev_loop)); 868 memset (loop, 0, sizeof (struct ev_loop));
858 869
859 loop_init (EV_A_ methods); 870 loop_init (EV_A_ flags);
860 871
861 if (ev_method (EV_A)) 872 if (ev_method (EV_A))
862 return loop; 873 return loop;
863 874
864 return 0; 875 return 0;
882#if EV_MULTIPLICITY 893#if EV_MULTIPLICITY
883struct ev_loop * 894struct ev_loop *
884#else 895#else
885int 896int
886#endif 897#endif
887ev_default_loop (int methods) 898ev_default_loop (unsigned int flags)
888{ 899{
889 if (sigpipe [0] == sigpipe [1]) 900 if (sigpipe [0] == sigpipe [1])
890 if (pipe (sigpipe)) 901 if (pipe (sigpipe))
891 return 0; 902 return 0;
892 903
896 struct ev_loop *loop = default_loop = &default_loop_struct; 907 struct ev_loop *loop = default_loop = &default_loop_struct;
897#else 908#else
898 default_loop = 1; 909 default_loop = 1;
899#endif 910#endif
900 911
901 loop_init (EV_A_ methods); 912 loop_init (EV_A_ flags);
902 913
903 if (ev_method (EV_A)) 914 if (ev_method (EV_A))
904 { 915 {
905 siginit (EV_A); 916 siginit (EV_A);
906 917
907#ifndef WIN32 918#ifndef _WIN32
908 ev_signal_init (&childev, childcb, SIGCHLD); 919 ev_signal_init (&childev, childcb, SIGCHLD);
909 ev_set_priority (&childev, EV_MAXPRI); 920 ev_set_priority (&childev, EV_MAXPRI);
910 ev_signal_start (EV_A_ &childev); 921 ev_signal_start (EV_A_ &childev);
911 ev_unref (EV_A); /* child watcher should not keep loop alive */ 922 ev_unref (EV_A); /* child watcher should not keep loop alive */
912#endif 923#endif
923{ 934{
924#if EV_MULTIPLICITY 935#if EV_MULTIPLICITY
925 struct ev_loop *loop = default_loop; 936 struct ev_loop *loop = default_loop;
926#endif 937#endif
927 938
928#ifndef WIN32 939#ifndef _WIN32
929 ev_ref (EV_A); /* child watcher */ 940 ev_ref (EV_A); /* child watcher */
930 ev_signal_stop (EV_A_ &childev); 941 ev_signal_stop (EV_A_ &childev);
931#endif 942#endif
932 943
933 ev_ref (EV_A); /* signal watcher */ 944 ev_ref (EV_A); /* signal watcher */
1020 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1031 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1021 1032
1022 /* first reschedule or stop timer */ 1033 /* first reschedule or stop timer */
1023 if (w->reschedule_cb) 1034 if (w->reschedule_cb)
1024 { 1035 {
1025 ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); 1036 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001);
1026
1027 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); 1037 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1028 downheap ((WT *)periodics, periodiccnt, 0); 1038 downheap ((WT *)periodics, periodiccnt, 0);
1029 } 1039 }
1030 else if (w->interval) 1040 else if (w->interval)
1031 { 1041 {
1350 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1360 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1351 1361
1352 if (((W)w)->active < timercnt--) 1362 if (((W)w)->active < timercnt--)
1353 { 1363 {
1354 timers [((W)w)->active - 1] = timers [timercnt]; 1364 timers [((W)w)->active - 1] = timers [timercnt];
1355 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1365 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1356 } 1366 }
1357 1367
1358 ((WT)w)->at -= mn_now; 1368 ((WT)w)->at -= mn_now;
1359 1369
1360 ev_stop (EV_A_ (W)w); 1370 ev_stop (EV_A_ (W)w);
1364ev_timer_again (EV_P_ struct ev_timer *w) 1374ev_timer_again (EV_P_ struct ev_timer *w)
1365{ 1375{
1366 if (ev_is_active (w)) 1376 if (ev_is_active (w))
1367 { 1377 {
1368 if (w->repeat) 1378 if (w->repeat)
1379 {
1380 ((WT)w)->at = mn_now + w->repeat;
1369 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); 1381 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1382 }
1370 else 1383 else
1371 ev_timer_stop (EV_A_ w); 1384 ev_timer_stop (EV_A_ w);
1372 } 1385 }
1373 else if (w->repeat) 1386 else if (w->repeat)
1374 ev_timer_start (EV_A_ w); 1387 ev_timer_start (EV_A_ w);
1408 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1421 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1409 1422
1410 if (((W)w)->active < periodiccnt--) 1423 if (((W)w)->active < periodiccnt--)
1411 { 1424 {
1412 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1425 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1413 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1426 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1414 } 1427 }
1415 1428
1416 ev_stop (EV_A_ (W)w); 1429 ev_stop (EV_A_ (W)w);
1417} 1430}
1418 1431
1438 1451
1439void 1452void
1440ev_idle_stop (EV_P_ struct ev_idle *w) 1453ev_idle_stop (EV_P_ struct ev_idle *w)
1441{ 1454{
1442 ev_clear_pending (EV_A_ (W)w); 1455 ev_clear_pending (EV_A_ (W)w);
1443 if (ev_is_active (w)) 1456 if (!ev_is_active (w))
1444 return; 1457 return;
1445 1458
1446 idles [((W)w)->active - 1] = idles [--idlecnt]; 1459 idles [((W)w)->active - 1] = idles [--idlecnt];
1447 ev_stop (EV_A_ (W)w); 1460 ev_stop (EV_A_ (W)w);
1448} 1461}
1460 1473
1461void 1474void
1462ev_prepare_stop (EV_P_ struct ev_prepare *w) 1475ev_prepare_stop (EV_P_ struct ev_prepare *w)
1463{ 1476{
1464 ev_clear_pending (EV_A_ (W)w); 1477 ev_clear_pending (EV_A_ (W)w);
1465 if (ev_is_active (w)) 1478 if (!ev_is_active (w))
1466 return; 1479 return;
1467 1480
1468 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1481 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1469 ev_stop (EV_A_ (W)w); 1482 ev_stop (EV_A_ (W)w);
1470} 1483}
1510 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); 1523 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1511 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1524 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1512 1525
1513 if (!((WL)w)->next) 1526 if (!((WL)w)->next)
1514 { 1527 {
1515#if WIN32 1528#if _WIN32
1516 signal (w->signum, sighandler); 1529 signal (w->signum, sighandler);
1517#else 1530#else
1518 struct sigaction sa; 1531 struct sigaction sa;
1519 sa.sa_handler = sighandler; 1532 sa.sa_handler = sighandler;
1520 sigfillset (&sa.sa_mask); 1533 sigfillset (&sa.sa_mask);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines