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

Comparing libev/ev.c (file contents):
Revision 1.193 by root, Sat Dec 22 05:47:58 2007 UTC vs.
Revision 1.206 by root, Fri Jan 25 15:45:08 2008 UTC

2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * modification, are permitted provided that the following conditions are 8 * tion, are permitted provided that the following conditions are met:
9 * met: 9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26 * OF THE POSSIBILITY OF SUCH DAMAGE.
10 * 27 *
11 * * Redistributions of source code must retain the above copyright 28 * Alternatively, the contents of this file may be used under the terms of
12 * notice, this list of conditions and the following disclaimer. 29 * the GNU General Public License ("GPL") version 2 or any later version,
13 * 30 * in which case the provisions of the GPL are applicable instead of
14 * * Redistributions in binary form must reproduce the above 31 * the above. If you wish to allow the use of your version of this file
15 * copyright notice, this list of conditions and the following 32 * only under the terms of the GPL and not to allow others to use your
16 * disclaimer in the documentation and/or other materials provided 33 * version of this file under the BSD license, indicate your decision
17 * with the distribution. 34 * by deleting the provisions above and replace them with the notice
18 * 35 * and other provisions required by the GPL. If you do not delete the
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 * provisions above, a recipient may use your version of this file under
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 * either the BSD or the GPL.
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 38 */
31 39
32#ifdef __cplusplus 40#ifdef __cplusplus
33extern "C" { 41extern "C" {
34#endif 42#endif
280 288
281typedef ev_watcher *W; 289typedef ev_watcher *W;
282typedef ev_watcher_list *WL; 290typedef ev_watcher_list *WL;
283typedef ev_watcher_time *WT; 291typedef ev_watcher_time *WT;
284 292
293#if EV_USE_MONOTONIC
294/* sig_atomic_t is used to avoid per-thread variables or locking but still */
295/* giving it a reasonably high chance of working on typical architetcures */
285static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 296static sig_atomic_t have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
297#endif
286 298
287#ifdef _WIN32 299#ifdef _WIN32
288# include "ev_win32.c" 300# include "ev_win32.c"
289#endif 301#endif
290 302
588 600
589#if EV_SELECT_IS_WINSOCKET 601#if EV_SELECT_IS_WINSOCKET
590 if (events) 602 if (events)
591 { 603 {
592 unsigned long argp; 604 unsigned long argp;
605 #ifdef EV_FD_TO_WIN32_HANDLE
606 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
607 #else
593 anfd->handle = _get_osfhandle (fd); 608 anfd->handle = _get_osfhandle (fd);
609 #endif
594 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); 610 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
595 } 611 }
596#endif 612#endif
597 613
598 { 614 {
851 867
852#ifndef _WIN32 868#ifndef _WIN32
853 869
854static ev_signal childev; 870static ev_signal childev;
855 871
872#ifndef WIFCONTINUED
873# define WIFCONTINUED(status) 0
874#endif
875
856void inline_speed 876void inline_speed
857child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 877child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
858{ 878{
859 ev_child *w; 879 ev_child *w;
880 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
860 881
861 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 882 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
883 {
862 if (w->pid == pid || !w->pid) 884 if ((w->pid == pid || !w->pid)
885 && (!traced || (w->flags & 1)))
863 { 886 {
864 ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ 887 ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */
865 w->rpid = pid; 888 w->rpid = pid;
866 w->rstatus = status; 889 w->rstatus = status;
867 ev_feed_event (EV_A_ (W)w, EV_CHILD); 890 ev_feed_event (EV_A_ (W)w, EV_CHILD);
868 } 891 }
892 }
869} 893}
870 894
871#ifndef WCONTINUED 895#ifndef WCONTINUED
872# define WCONTINUED 0 896# define WCONTINUED 0
873#endif 897#endif
970} 994}
971 995
972unsigned int 996unsigned int
973ev_embeddable_backends (void) 997ev_embeddable_backends (void)
974{ 998{
999 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
1000
975 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 1001 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
976 return EVBACKEND_KQUEUE 1002 /* please fix it and tell me how to detect the fix */
977 | EVBACKEND_PORT; 1003 flags &= ~EVBACKEND_EPOLL;
1004
1005 return flags;
978} 1006}
979 1007
980unsigned int 1008unsigned int
981ev_backend (EV_P) 1009ev_backend (EV_P)
982{ 1010{
1146 1174
1147 while (pipe (sigpipe)) 1175 while (pipe (sigpipe))
1148 syserr ("(libev) error creating pipe"); 1176 syserr ("(libev) error creating pipe");
1149 1177
1150 siginit (EV_A); 1178 siginit (EV_A);
1179 sigcb (EV_A_ &sigev, EV_READ);
1151 } 1180 }
1152 1181
1153 postfork = 0; 1182 postfork = 0;
1154} 1183}
1155 1184
1177} 1206}
1178 1207
1179void 1208void
1180ev_loop_fork (EV_P) 1209ev_loop_fork (EV_P)
1181{ 1210{
1182 postfork = 1; 1211 postfork = 1; /* must be in line with ev_default_fork */
1183} 1212}
1184 1213
1185#endif 1214#endif
1186 1215
1187#if EV_MULTIPLICITY 1216#if EV_MULTIPLICITY
1251#if EV_MULTIPLICITY 1280#if EV_MULTIPLICITY
1252 struct ev_loop *loop = ev_default_loop_ptr; 1281 struct ev_loop *loop = ev_default_loop_ptr;
1253#endif 1282#endif
1254 1283
1255 if (backend) 1284 if (backend)
1256 postfork = 1; 1285 postfork = 1; /* must be in line with ev_loop_fork */
1257} 1286}
1258 1287
1259/*****************************************************************************/ 1288/*****************************************************************************/
1260 1289
1261void 1290void
2264 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); 2293 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io));
2265 2294
2266 if (ev_cb (w)) 2295 if (ev_cb (w))
2267 ev_feed_event (EV_A_ (W)w, EV_EMBED); 2296 ev_feed_event (EV_A_ (W)w, EV_EMBED);
2268 else 2297 else
2269 ev_embed_sweep (loop, w); 2298 ev_loop (w->other, EVLOOP_NONBLOCK);
2270} 2299}
2271 2300
2272static void 2301static void
2273embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) 2302embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
2274{ 2303{
2275 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); 2304 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare));
2276 2305
2277 fd_reify (w->other); 2306 {
2307 struct ev_loop *loop = w->other;
2308
2309 while (fdchangecnt)
2310 {
2311 fd_reify (EV_A);
2312 ev_loop (EV_A_ EVLOOP_NONBLOCK);
2313 }
2314 }
2278} 2315}
2316
2317#if 0
2318static void
2319embed_idle_cb (EV_P_ ev_idle *idle, int revents)
2320{
2321 ev_idle_stop (EV_A_ idle);
2322}
2323#endif
2279 2324
2280void 2325void
2281ev_embed_start (EV_P_ ev_embed *w) 2326ev_embed_start (EV_P_ ev_embed *w)
2282{ 2327{
2283 if (expect_false (ev_is_active (w))) 2328 if (expect_false (ev_is_active (w)))
2294 2339
2295 ev_prepare_init (&w->prepare, embed_prepare_cb); 2340 ev_prepare_init (&w->prepare, embed_prepare_cb);
2296 ev_set_priority (&w->prepare, EV_MINPRI); 2341 ev_set_priority (&w->prepare, EV_MINPRI);
2297 ev_prepare_start (EV_A_ &w->prepare); 2342 ev_prepare_start (EV_A_ &w->prepare);
2298 2343
2344 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/
2345
2299 ev_start (EV_A_ (W)w, 1); 2346 ev_start (EV_A_ (W)w, 1);
2300} 2347}
2301 2348
2302void 2349void
2303ev_embed_stop (EV_P_ ev_embed *w) 2350ev_embed_stop (EV_P_ ev_embed *w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines