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

Comparing libev/ev.c (file contents):
Revision 1.114 by root, Mon Nov 12 20:03:39 2007 UTC vs.
Revision 1.119 by root, Fri Nov 16 01:43:52 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 */
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}
1160ev_loop (EV_P_ int flags) 1181ev_loop (EV_P_ int flags)
1161{ 1182{
1162 double block; 1183 double block;
1163 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; 1184 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
1164 1185
1165 do 1186 while (activecnt)
1166 { 1187 {
1167 /* queue check watchers (and execute them) */ 1188 /* queue check watchers (and execute them) */
1168 if (expect_false (preparecnt)) 1189 if (expect_false (preparecnt))
1169 { 1190 {
1170 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1191 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1233 /* queue check watchers, to be executed first */ 1254 /* queue check watchers, to be executed first */
1234 if (checkcnt) 1255 if (checkcnt)
1235 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1256 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1236 1257
1237 call_pending (EV_A); 1258 call_pending (EV_A);
1259
1260 if (loop_done)
1261 break;
1238 } 1262 }
1239 while (activecnt && !loop_done);
1240 1263
1241 if (loop_done != 2) 1264 if (loop_done != 2)
1242 loop_done = 0; 1265 loop_done = 0;
1243} 1266}
1244 1267
1514 1537
1515void 1538void
1516ev_signal_start (EV_P_ struct ev_signal *w) 1539ev_signal_start (EV_P_ struct ev_signal *w)
1517{ 1540{
1518#if EV_MULTIPLICITY 1541#if EV_MULTIPLICITY
1519 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));
1520#endif 1543#endif
1521 if (ev_is_active (w)) 1544 if (ev_is_active (w))
1522 return; 1545 return;
1523 1546
1524 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));
1557 1580
1558void 1581void
1559ev_child_start (EV_P_ struct ev_child *w) 1582ev_child_start (EV_P_ struct ev_child *w)
1560{ 1583{
1561#if EV_MULTIPLICITY 1584#if EV_MULTIPLICITY
1562 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));
1563#endif 1586#endif
1564 if (ev_is_active (w)) 1587 if (ev_is_active (w))
1565 return; 1588 return;
1566 1589
1567 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