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

Comparing libev/ev.c (file contents):
Revision 1.115 by root, Wed Nov 14 04:53:21 2007 UTC vs.
Revision 1.120 by root, Fri Nov 16 01:54:25 2007 UTC

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
62# endif 62# endif
63 63
64# if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT)
65# define EV_USE_PORT 1
66# endif
67
64#endif 68#endif
65 69
66#include <math.h> 70#include <math.h>
67#include <stdlib.h> 71#include <stdlib.h>
68#include <fcntl.h> 72#include <fcntl.h>
93 97
94#ifndef EV_USE_MONOTONIC 98#ifndef EV_USE_MONOTONIC
95# define EV_USE_MONOTONIC 1 99# define EV_USE_MONOTONIC 1
96#endif 100#endif
97 101
102#ifndef EV_USE_REALTIME
103# define EV_USE_REALTIME 1
104#endif
105
98#ifndef EV_USE_SELECT 106#ifndef EV_USE_SELECT
99# define EV_USE_SELECT 1 107# define EV_USE_SELECT 1
100# define EV_SELECT_USE_FD_SET 1 108# define EV_SELECT_USE_FD_SET 1
101#endif 109#endif
102 110
114 122
115#ifndef EV_USE_KQUEUE 123#ifndef EV_USE_KQUEUE
116# define EV_USE_KQUEUE 0 124# define EV_USE_KQUEUE 0
117#endif 125#endif
118 126
119#ifndef EV_USE_REALTIME 127#ifndef EV_USE_PORT
120# define EV_USE_REALTIME 1 128# define EV_USE_PORT 0
121#endif 129#endif
122 130
123/**/ 131/**/
124 132
125/* darwin simply cannot be helped */ 133/* darwin simply cannot be helped */
143#endif 151#endif
144 152
145/**/ 153/**/
146 154
147#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 155#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
148#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 156#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
149#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 157#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
150/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 158/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
151 159
152#ifdef EV_H 160#ifdef EV_H
153# include EV_H 161# include EV_H
154#else 162#else
155# include "ev.h" 163# include "ev.h"
258 #include "ev_vars.h" 266 #include "ev_vars.h"
259 #undef VAR 267 #undef VAR
260 }; 268 };
261 #include "ev_wrap.h" 269 #include "ev_wrap.h"
262 270
263 struct ev_loop default_loop_struct; 271 static struct ev_loop default_loop_struct;
264 static struct ev_loop *default_loop; 272 struct ev_loop *ev_default_loop_ptr;
265 273
266#else 274#else
267 275
268 ev_tstamp ev_rt_now; 276 ev_tstamp ev_rt_now;
269 #define VAR(name,decl) static decl; 277 #define VAR(name,decl) static decl;
270 #include "ev_vars.h" 278 #include "ev_vars.h"
271 #undef VAR 279 #undef VAR
272 280
273 static int default_loop; 281 static int ev_default_loop_ptr;
274 282
275#endif 283#endif
276 284
277/*****************************************************************************/ 285/*****************************************************************************/
278 286
614ev_feed_signal_event (EV_P_ int signum) 622ev_feed_signal_event (EV_P_ int signum)
615{ 623{
616 WL w; 624 WL w;
617 625
618#if EV_MULTIPLICITY 626#if EV_MULTIPLICITY
619 assert (("feeding signal events is only supported in the default loop", loop == default_loop)); 627 assert (("feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr));
620#endif 628#endif
621 629
622 --signum; 630 --signum;
623 631
624 if (signum < 0 || signum >= signalmax) 632 if (signum < 0 || signum >= signalmax)
710 718
711#endif 719#endif
712 720
713/*****************************************************************************/ 721/*****************************************************************************/
714 722
723#if EV_USE_PORT
724# include "ev_port.c"
725#endif
715#if EV_USE_KQUEUE 726#if EV_USE_KQUEUE
716# include "ev_kqueue.c" 727# include "ev_kqueue.c"
717#endif 728#endif
718#if EV_USE_EPOLL 729#if EV_USE_EPOLL
719# include "ev_epoll.c" 730# include "ev_epoll.c"
778 789
779 if (!(flags & 0x0000ffff)) 790 if (!(flags & 0x0000ffff))
780 flags |= 0x0000ffff; 791 flags |= 0x0000ffff;
781 792
782 method = 0; 793 method = 0;
794#if EV_USE_PORT
795 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags);
796#endif
783#if EV_USE_KQUEUE 797#if EV_USE_KQUEUE
784 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 798 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
785#endif 799#endif
786#if EV_USE_EPOLL 800#if EV_USE_EPOLL
787 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 801 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
801void 815void
802loop_destroy (EV_P) 816loop_destroy (EV_P)
803{ 817{
804 int i; 818 int i;
805 819
820#if EV_USE_PORT
821 if (method == EVMETHOD_PORT ) port_destroy (EV_A);
822#endif
806#if EV_USE_KQUEUE 823#if EV_USE_KQUEUE
807 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 824 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
808#endif 825#endif
809#if EV_USE_EPOLL 826#if EV_USE_EPOLL
810 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 827 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
833} 850}
834 851
835static void 852static void
836loop_fork (EV_P) 853loop_fork (EV_P)
837{ 854{
855#if EV_USE_PORT
856 if (method == EVMETHOD_PORT ) port_fork (EV_A);
857#endif
858#if EV_USE_KQUEUE
859 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
860#endif
838#if EV_USE_EPOLL 861#if EV_USE_EPOLL
839 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 862 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
840#endif
841#if EV_USE_KQUEUE
842 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
843#endif 863#endif
844 864
845 if (ev_is_active (&sigev)) 865 if (ev_is_active (&sigev))
846 { 866 {
847 /* default loop */ 867 /* default loop */
891 911
892#endif 912#endif
893 913
894#if EV_MULTIPLICITY 914#if EV_MULTIPLICITY
895struct ev_loop * 915struct ev_loop *
916ev_default_loop_ (unsigned int flags)
896#else 917#else
897int 918int
898#endif
899ev_default_loop (unsigned int flags) 919ev_default_loop (unsigned int flags)
920#endif
900{ 921{
901 if (sigpipe [0] == sigpipe [1]) 922 if (sigpipe [0] == sigpipe [1])
902 if (pipe (sigpipe)) 923 if (pipe (sigpipe))
903 return 0; 924 return 0;
904 925
905 if (!default_loop) 926 if (!ev_default_loop_ptr)
906 { 927 {
907#if EV_MULTIPLICITY 928#if EV_MULTIPLICITY
908 struct ev_loop *loop = default_loop = &default_loop_struct; 929 struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct;
909#else 930#else
910 default_loop = 1; 931 ev_default_loop_ptr = 1;
911#endif 932#endif
912 933
913 loop_init (EV_A_ flags); 934 loop_init (EV_A_ flags);
914 935
915 if (ev_method (EV_A)) 936 if (ev_method (EV_A))
922 ev_signal_start (EV_A_ &childev); 943 ev_signal_start (EV_A_ &childev);
923 ev_unref (EV_A); /* child watcher should not keep loop alive */ 944 ev_unref (EV_A); /* child watcher should not keep loop alive */
924#endif 945#endif
925 } 946 }
926 else 947 else
927 default_loop = 0; 948 ev_default_loop_ptr = 0;
928 } 949 }
929 950
930 return default_loop; 951 return ev_default_loop_ptr;
931} 952}
932 953
933void 954void
934ev_default_destroy (void) 955ev_default_destroy (void)
935{ 956{
936#if EV_MULTIPLICITY 957#if EV_MULTIPLICITY
937 struct ev_loop *loop = default_loop; 958 struct ev_loop *loop = ev_default_loop_ptr;
938#endif 959#endif
939 960
940#ifndef _WIN32 961#ifndef _WIN32
941 ev_ref (EV_A); /* child watcher */ 962 ev_ref (EV_A); /* child watcher */
942 ev_signal_stop (EV_A_ &childev); 963 ev_signal_stop (EV_A_ &childev);
953 974
954void 975void
955ev_default_fork (void) 976ev_default_fork (void)
956{ 977{
957#if EV_MULTIPLICITY 978#if EV_MULTIPLICITY
958 struct ev_loop *loop = default_loop; 979 struct ev_loop *loop = ev_default_loop_ptr;
959#endif 980#endif
960 981
961 if (method) 982 if (method)
962 postfork = 1; 983 postfork = 1;
963} 984}
1516 1537
1517void 1538void
1518ev_signal_start (EV_P_ struct ev_signal *w) 1539ev_signal_start (EV_P_ struct ev_signal *w)
1519{ 1540{
1520#if EV_MULTIPLICITY 1541#if EV_MULTIPLICITY
1521 assert (("signal watchers are only supported in the default loop", loop == default_loop)); 1542 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1522#endif 1543#endif
1523 if (ev_is_active (w)) 1544 if (ev_is_active (w))
1524 return; 1545 return;
1525 1546
1526 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1547 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1559 1580
1560void 1581void
1561ev_child_start (EV_P_ struct ev_child *w) 1582ev_child_start (EV_P_ struct ev_child *w)
1562{ 1583{
1563#if EV_MULTIPLICITY 1584#if EV_MULTIPLICITY
1564 assert (("child watchers are only supported in the default loop", loop == default_loop)); 1585 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1565#endif 1586#endif
1566 if (ev_is_active (w)) 1587 if (ev_is_active (w))
1567 return; 1588 return;
1568 1589
1569 ev_start (EV_A_ (W)w, 1); 1590 ev_start (EV_A_ (W)w, 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines