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

Comparing libev/ev.c (file contents):
Revision 1.98 by root, Sun Nov 11 02:05:20 2007 UTC vs.
Revision 1.109 by root, Mon Nov 12 05:53:55 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
166#ifdef WIN32 180#ifdef _WIN32
167# include "ev_win32.c" 181# include "ev_win32.c"
168#endif 182#endif
169 183
170/*****************************************************************************/ 184/*****************************************************************************/
171 185
220typedef struct 234typedef struct
221{ 235{
222 WL head; 236 WL head;
223 unsigned char events; 237 unsigned char events;
224 unsigned char reify; 238 unsigned char reify;
239#if EV_SELECT_IS_WINSOCKET
240 SOCKET handle;
241#endif
225} ANFD; 242} ANFD;
226 243
227typedef struct 244typedef struct
228{ 245{
229 W w; 246 W w;
233#if EV_MULTIPLICITY 250#if EV_MULTIPLICITY
234 251
235 struct ev_loop 252 struct ev_loop
236 { 253 {
237 ev_tstamp ev_rt_now; 254 ev_tstamp ev_rt_now;
255 #define ev_rt_now ((loop)->ev_rt_now)
238 #define VAR(name,decl) decl; 256 #define VAR(name,decl) decl;
239 #include "ev_vars.h" 257 #include "ev_vars.h"
240 #undef VAR 258 #undef VAR
241 }; 259 };
242 #include "ev_wrap.h" 260 #include "ev_wrap.h"
292{ 310{
293 return ev_rt_now; 311 return ev_rt_now;
294} 312}
295#endif 313#endif
296 314
297#define array_roundsize(type,n) ((n) | 4 & ~3) 315#define array_roundsize(type,n) (((n) | 4) & ~3)
298 316
299#define array_needsize(type,base,cur,cnt,init) \ 317#define array_needsize(type,base,cur,cnt,init) \
300 if (expect_false ((cnt) > cur)) \ 318 if (expect_false ((cnt) > cur)) \
301 { \ 319 { \
302 int newcnt = cur; \ 320 int newcnt = cur; \
317 stem ## max = array_roundsize (stem ## cnt >> 1); \ 335 stem ## max = array_roundsize (stem ## cnt >> 1); \
318 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 336 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
319 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 337 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
320 } 338 }
321 339
322/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
323/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
324#define array_free_microshit(stem) \
325 ev_free (stem ## s); stem ## cnt = stem ## max = 0;
326
327#define array_free(stem, idx) \ 340#define array_free(stem, idx) \
328 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;
329 342
330/*****************************************************************************/ 343/*****************************************************************************/
331 344
405 int events = 0; 418 int events = 0;
406 419
407 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)
408 events |= w->events; 421 events |= w->events;
409 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
410 anfd->reify = 0; 432 anfd->reify = 0;
411 433
412 method_modify (EV_A_ fd, anfd->events, events); 434 method_modify (EV_A_ fd, anfd->events, events);
413 anfd->events = events; 435 anfd->events = events;
414 } 436 }
442} 464}
443 465
444static int 466static int
445fd_valid (int fd) 467fd_valid (int fd)
446{ 468{
447#ifdef WIN32 469#ifdef _WIN32
448 return !!win32_get_osfhandle (fd); 470 return _get_osfhandle (fd) != -1;
449#else 471#else
450 return fcntl (fd, F_GETFD) != -1; 472 return fcntl (fd, F_GETFD) != -1;
451#endif 473#endif
452} 474}
453 475
534 heap [k] = w; 556 heap [k] = w;
535 ((W)heap [k])->active = k + 1; 557 ((W)heap [k])->active = k + 1;
536} 558}
537 559
538inline void 560inline void
539adjustheap (WT *heap, int N, int k, ev_tstamp at) 561adjustheap (WT *heap, int N, int k)
540{ 562{
541 ev_tstamp old_at = heap [k]->at; 563 upheap (heap, k);
542 heap [k]->at = at;
543
544 if (old_at < at)
545 downheap (heap, N, k); 564 downheap (heap, N, k);
546 else
547 upheap (heap, k);
548} 565}
549 566
550/*****************************************************************************/ 567/*****************************************************************************/
551 568
552typedef struct 569typedef struct
575} 592}
576 593
577static void 594static void
578sighandler (int signum) 595sighandler (int signum)
579{ 596{
580#if WIN32 597#if _WIN32
581 signal (signum, sighandler); 598 signal (signum, sighandler);
582#endif 599#endif
583 600
584 signals [signum - 1].gotsig = 1; 601 signals [signum - 1].gotsig = 1;
585 602
586 if (!gotsig) 603 if (!gotsig)
587 { 604 {
588 int old_errno = errno; 605 int old_errno = errno;
589 gotsig = 1; 606 gotsig = 1;
590#ifdef WIN32
591 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
592#else
593 write (sigpipe [1], &signum, 1); 607 write (sigpipe [1], &signum, 1);
594#endif
595 errno = old_errno; 608 errno = old_errno;
596 } 609 }
597} 610}
598 611
599void 612void
619static void 632static void
620sigcb (EV_P_ struct ev_io *iow, int revents) 633sigcb (EV_P_ struct ev_io *iow, int revents)
621{ 634{
622 int signum; 635 int signum;
623 636
624#ifdef WIN32
625 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
626#else
627 read (sigpipe [0], &revents, 1); 637 read (sigpipe [0], &revents, 1);
628#endif
629 gotsig = 0; 638 gotsig = 0;
630 639
631 for (signum = signalmax; signum--; ) 640 for (signum = signalmax; signum--; )
632 if (signals [signum].gotsig) 641 if (signals [signum].gotsig)
633 ev_feed_signal_event (EV_A_ signum + 1); 642 ev_feed_signal_event (EV_A_ signum + 1);
634} 643}
635 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
636static void 657static void
637siginit (EV_P) 658siginit (EV_P)
638{ 659{
639#ifndef WIN32 660 fd_intern (sigpipe [0]);
640 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); 661 fd_intern (sigpipe [1]);
641 fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
642
643 /* rather than sort out wether we really need nb, set it */
644 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
645 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
646#endif
647 662
648 ev_io_set (&sigev, sigpipe [0], EV_READ); 663 ev_io_set (&sigev, sigpipe [0], EV_READ);
649 ev_io_start (EV_A_ &sigev); 664 ev_io_start (EV_A_ &sigev);
650 ev_unref (EV_A); /* child watcher should not keep loop alive */ 665 ev_unref (EV_A); /* child watcher should not keep loop alive */
651} 666}
652 667
653/*****************************************************************************/ 668/*****************************************************************************/
654 669
655static struct ev_child *childs [PID_HASHSIZE]; 670static struct ev_child *childs [PID_HASHSIZE];
656 671
657#ifndef WIN32 672#ifndef _WIN32
658 673
659static struct ev_signal childev; 674static struct ev_signal childev;
660 675
661#ifndef WCONTINUED 676#ifndef WCONTINUED
662# define WCONTINUED 0 677# define WCONTINUED 0
723 738
724/* 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 */
725static int 740static int
726enable_secure (void) 741enable_secure (void)
727{ 742{
728#ifdef WIN32 743#ifdef _WIN32
729 return 0; 744 return 0;
730#else 745#else
731 return getuid () != geteuid () 746 return getuid () != geteuid ()
732 || getgid () != getegid (); 747 || getgid () != getegid ();
733#endif 748#endif
738{ 753{
739 return method; 754 return method;
740} 755}
741 756
742static void 757static void
743loop_init (EV_P_ int methods) 758loop_init (EV_P_ unsigned int flags)
744{ 759{
745 if (!method) 760 if (!method)
746 { 761 {
747#if EV_USE_MONOTONIC 762#if EV_USE_MONOTONIC
748 { 763 {
755 ev_rt_now = ev_time (); 770 ev_rt_now = ev_time ();
756 mn_now = get_clock (); 771 mn_now = get_clock ();
757 now_floor = mn_now; 772 now_floor = mn_now;
758 rtmn_diff = ev_rt_now - mn_now; 773 rtmn_diff = ev_rt_now - mn_now;
759 774
760 if (methods == EVMETHOD_AUTO) 775 if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS"))
761 if (!enable_secure () && getenv ("LIBEV_METHODS"))
762 methods = atoi (getenv ("LIBEV_METHODS")); 776 flags = atoi (getenv ("LIBEV_FLAGS"));
763 else 777
764 methods = EVMETHOD_ANY; 778 if (!(flags & 0x0000ffff))
779 flags |= 0x0000ffff;
765 780
766 method = 0; 781 method = 0;
767#if EV_USE_WIN32
768 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
769#endif
770#if EV_USE_KQUEUE 782#if EV_USE_KQUEUE
771 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 783 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
772#endif 784#endif
773#if EV_USE_EPOLL 785#if EV_USE_EPOLL
774 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 786 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
775#endif 787#endif
776#if EV_USE_POLL 788#if EV_USE_POLL
777 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 789 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags);
778#endif 790#endif
779#if EV_USE_SELECT 791#if EV_USE_SELECT
780 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 792 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags);
781#endif 793#endif
782 794
783 ev_init (&sigev, sigcb); 795 ev_init (&sigev, sigcb);
784 ev_set_priority (&sigev, EV_MAXPRI); 796 ev_set_priority (&sigev, EV_MAXPRI);
785 } 797 }
788void 800void
789loop_destroy (EV_P) 801loop_destroy (EV_P)
790{ 802{
791 int i; 803 int i;
792 804
793#if EV_USE_WIN32
794 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
795#endif
796#if EV_USE_KQUEUE 805#if EV_USE_KQUEUE
797 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 806 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
798#endif 807#endif
799#if EV_USE_EPOLL 808#if EV_USE_EPOLL
800 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 809 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
808 817
809 for (i = NUMPRI; i--; ) 818 for (i = NUMPRI; i--; )
810 array_free (pending, [i]); 819 array_free (pending, [i]);
811 820
812 /* have to use the microsoft-never-gets-it-right macro */ 821 /* have to use the microsoft-never-gets-it-right macro */
813 array_free_microshit (fdchange); 822 array_free (fdchange, EMPTY);
814 array_free_microshit (timer); 823 array_free (timer, EMPTY);
815#if EV_PERIODICS 824#if EV_PERIODICS
816 array_free_microshit (periodic); 825 array_free (periodic, EMPTY);
817#endif 826#endif
818 array_free_microshit (idle); 827 array_free (idle, EMPTY);
819 array_free_microshit (prepare); 828 array_free (prepare, EMPTY);
820 array_free_microshit (check); 829 array_free (check, EMPTY);
821 830
822 method = 0; 831 method = 0;
823} 832}
824 833
825static void 834static void
850 postfork = 0; 859 postfork = 0;
851} 860}
852 861
853#if EV_MULTIPLICITY 862#if EV_MULTIPLICITY
854struct ev_loop * 863struct ev_loop *
855ev_loop_new (int methods) 864ev_loop_new (unsigned int flags)
856{ 865{
857 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));
858 867
859 memset (loop, 0, sizeof (struct ev_loop)); 868 memset (loop, 0, sizeof (struct ev_loop));
860 869
861 loop_init (EV_A_ methods); 870 loop_init (EV_A_ flags);
862 871
863 if (ev_method (EV_A)) 872 if (ev_method (EV_A))
864 return loop; 873 return loop;
865 874
866 return 0; 875 return 0;
884#if EV_MULTIPLICITY 893#if EV_MULTIPLICITY
885struct ev_loop * 894struct ev_loop *
886#else 895#else
887int 896int
888#endif 897#endif
889ev_default_loop (int methods) 898ev_default_loop (unsigned int flags)
890{ 899{
891 if (sigpipe [0] == sigpipe [1]) 900 if (sigpipe [0] == sigpipe [1])
892 if (pipe (sigpipe)) 901 if (pipe (sigpipe))
893 return 0; 902 return 0;
894 903
904 913
905 if (ev_method (EV_A)) 914 if (ev_method (EV_A))
906 { 915 {
907 siginit (EV_A); 916 siginit (EV_A);
908 917
909#ifndef WIN32 918#ifndef _WIN32
910 ev_signal_init (&childev, childcb, SIGCHLD); 919 ev_signal_init (&childev, childcb, SIGCHLD);
911 ev_set_priority (&childev, EV_MAXPRI); 920 ev_set_priority (&childev, EV_MAXPRI);
912 ev_signal_start (EV_A_ &childev); 921 ev_signal_start (EV_A_ &childev);
913 ev_unref (EV_A); /* child watcher should not keep loop alive */ 922 ev_unref (EV_A); /* child watcher should not keep loop alive */
914#endif 923#endif
925{ 934{
926#if EV_MULTIPLICITY 935#if EV_MULTIPLICITY
927 struct ev_loop *loop = default_loop; 936 struct ev_loop *loop = default_loop;
928#endif 937#endif
929 938
930#ifndef WIN32 939#ifndef _WIN32
931 ev_ref (EV_A); /* child watcher */ 940 ev_ref (EV_A); /* child watcher */
932 ev_signal_stop (EV_A_ &childev); 941 ev_signal_stop (EV_A_ &childev);
933#endif 942#endif
934 943
935 ev_ref (EV_A); /* signal watcher */ 944 ev_ref (EV_A); /* signal watcher */
1022 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1031 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1023 1032
1024 /* first reschedule or stop timer */ 1033 /* first reschedule or stop timer */
1025 if (w->reschedule_cb) 1034 if (w->reschedule_cb)
1026 { 1035 {
1027 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);
1028
1029 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));
1030 downheap ((WT *)periodics, periodiccnt, 0); 1038 downheap ((WT *)periodics, periodiccnt, 0);
1031 } 1039 }
1032 else if (w->interval) 1040 else if (w->interval)
1033 { 1041 {
1352 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1360 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1353 1361
1354 if (((W)w)->active < timercnt--) 1362 if (((W)w)->active < timercnt--)
1355 { 1363 {
1356 timers [((W)w)->active - 1] = timers [timercnt]; 1364 timers [((W)w)->active - 1] = timers [timercnt];
1357 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1365 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1358 } 1366 }
1359 1367
1360 ((WT)w)->at -= mn_now; 1368 ((WT)w)->at -= mn_now;
1361 1369
1362 ev_stop (EV_A_ (W)w); 1370 ev_stop (EV_A_ (W)w);
1366ev_timer_again (EV_P_ struct ev_timer *w) 1374ev_timer_again (EV_P_ struct ev_timer *w)
1367{ 1375{
1368 if (ev_is_active (w)) 1376 if (ev_is_active (w))
1369 { 1377 {
1370 if (w->repeat) 1378 if (w->repeat)
1379 {
1380 ((WT)w)->at = mn_now + w->repeat;
1371 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); 1381 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1382 }
1372 else 1383 else
1373 ev_timer_stop (EV_A_ w); 1384 ev_timer_stop (EV_A_ w);
1374 } 1385 }
1375 else if (w->repeat) 1386 else if (w->repeat)
1376 ev_timer_start (EV_A_ w); 1387 ev_timer_start (EV_A_ w);
1410 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1421 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1411 1422
1412 if (((W)w)->active < periodiccnt--) 1423 if (((W)w)->active < periodiccnt--)
1413 { 1424 {
1414 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1425 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1415 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1426 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1416 } 1427 }
1417 1428
1418 ev_stop (EV_A_ (W)w); 1429 ev_stop (EV_A_ (W)w);
1419} 1430}
1420 1431
1440 1451
1441void 1452void
1442ev_idle_stop (EV_P_ struct ev_idle *w) 1453ev_idle_stop (EV_P_ struct ev_idle *w)
1443{ 1454{
1444 ev_clear_pending (EV_A_ (W)w); 1455 ev_clear_pending (EV_A_ (W)w);
1445 if (ev_is_active (w)) 1456 if (!ev_is_active (w))
1446 return; 1457 return;
1447 1458
1448 idles [((W)w)->active - 1] = idles [--idlecnt]; 1459 idles [((W)w)->active - 1] = idles [--idlecnt];
1449 ev_stop (EV_A_ (W)w); 1460 ev_stop (EV_A_ (W)w);
1450} 1461}
1462 1473
1463void 1474void
1464ev_prepare_stop (EV_P_ struct ev_prepare *w) 1475ev_prepare_stop (EV_P_ struct ev_prepare *w)
1465{ 1476{
1466 ev_clear_pending (EV_A_ (W)w); 1477 ev_clear_pending (EV_A_ (W)w);
1467 if (ev_is_active (w)) 1478 if (!ev_is_active (w))
1468 return; 1479 return;
1469 1480
1470 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1481 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1471 ev_stop (EV_A_ (W)w); 1482 ev_stop (EV_A_ (W)w);
1472} 1483}
1512 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); 1523 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1513 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1524 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1514 1525
1515 if (!((WL)w)->next) 1526 if (!((WL)w)->next)
1516 { 1527 {
1517#if WIN32 1528#if _WIN32
1518 signal (w->signum, sighandler); 1529 signal (w->signum, sighandler);
1519#else 1530#else
1520 struct sigaction sa; 1531 struct sigaction sa;
1521 sa.sa_handler = sighandler; 1532 sa.sa_handler = sighandler;
1522 sigfillset (&sa.sa_mask); 1533 sigfillset (&sa.sa_mask);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines