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

Comparing libev/ev.c (file contents):
Revision 1.147 by root, Tue Nov 27 10:59:11 2007 UTC vs.
Revision 1.150 by root, Tue Nov 27 19:41:52 2007 UTC

156 156
157#ifndef EV_USE_PORT 157#ifndef EV_USE_PORT
158# define EV_USE_PORT 0 158# define EV_USE_PORT 0
159#endif 159#endif
160 160
161#ifndef EV_PID_HASHSIZE
162# if EV_MINIMAL
163# define EV_PID_HASHSIZE 1
164# else
165# define EV_PID_HASHSIZE 16
166# endif
167#endif
168
161/**/ 169/**/
162 170
163#ifndef CLOCK_MONOTONIC 171#ifndef CLOCK_MONOTONIC
164# undef EV_USE_MONOTONIC 172# undef EV_USE_MONOTONIC
165# define EV_USE_MONOTONIC 0 173# define EV_USE_MONOTONIC 0
176 184
177/**/ 185/**/
178 186
179#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 187#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
180#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 188#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
181#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
182/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ 189/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
183 190
184#ifdef EV_H 191#ifdef EV_H
185# include EV_H 192# include EV_H
186#else 193#else
246 perror (msg); 253 perror (msg);
247 abort (); 254 abort ();
248 } 255 }
249} 256}
250 257
251static void *(*alloc)(void *ptr, long size); 258static void *(*alloc)(void *ptr, size_t size) = realloc;
252 259
253void 260void
254ev_set_allocator (void *(*cb)(void *ptr, long size)) 261ev_set_allocator (void *(*cb)(void *ptr, size_t size))
255{ 262{
256 alloc = cb; 263 alloc = cb;
257} 264}
258 265
259static void * 266inline_speed void *
260ev_realloc (void *ptr, long size) 267ev_realloc (void *ptr, size_t size)
261{ 268{
262 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); 269 ptr = alloc (ptr, size);
263 270
264 if (!ptr && size) 271 if (!ptr && size)
265 { 272 {
266 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 273 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", (long)size);
267 abort (); 274 abort ();
268 } 275 }
269 276
270 return ptr; 277 return ptr;
271} 278}
709 ev_unref (EV_A); /* child watcher should not keep loop alive */ 716 ev_unref (EV_A); /* child watcher should not keep loop alive */
710} 717}
711 718
712/*****************************************************************************/ 719/*****************************************************************************/
713 720
714static ev_child *childs [PID_HASHSIZE]; 721static ev_child *childs [EV_PID_HASHSIZE];
715 722
716#ifndef _WIN32 723#ifndef _WIN32
717 724
718static ev_signal childev; 725static ev_signal childev;
719 726
720void inline_speed 727void inline_speed
721child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 728child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
722{ 729{
723 ev_child *w; 730 ev_child *w;
724 731
725 for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 732 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
726 if (w->pid == pid || !w->pid) 733 if (w->pid == pid || !w->pid)
727 { 734 {
728 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 735 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
729 w->rpid = pid; 736 w->rpid = pid;
730 w->rstatus = status; 737 w->rstatus = status;
751 /* make sure we are called again until all childs have been reaped */ 758 /* make sure we are called again until all childs have been reaped */
752 /* we need to do it this way so that the callback gets called before we continue */ 759 /* we need to do it this way so that the callback gets called before we continue */
753 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 760 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
754 761
755 child_reap (EV_A_ sw, pid, pid, status); 762 child_reap (EV_A_ sw, pid, pid, status);
763 if (EV_PID_HASHSIZE > 1)
756 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ 764 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
757} 765}
758 766
759#endif 767#endif
760 768
761/*****************************************************************************/ 769/*****************************************************************************/
1277 : EVUNLOOP_CANCEL; 1285 : EVUNLOOP_CANCEL;
1278 1286
1279 while (activecnt) 1287 while (activecnt)
1280 { 1288 {
1281 /* we might have forked, so reify kernel state if necessary */ 1289 /* we might have forked, so reify kernel state if necessary */
1290 #if EV_FORK_ENABLE
1282 if (expect_false (postfork)) 1291 if (expect_false (postfork))
1283 if (forkcnt) 1292 if (forkcnt)
1284 { 1293 {
1285 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 1294 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1286 call_pending (EV_A); 1295 call_pending (EV_A);
1287 } 1296 }
1297 #endif
1288 1298
1289 /* queue check watchers (and execute them) */ 1299 /* queue check watchers (and execute them) */
1290 if (expect_false (preparecnt)) 1300 if (expect_false (preparecnt))
1291 { 1301 {
1292 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1302 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1623#endif 1633#endif
1624 if (expect_false (ev_is_active (w))) 1634 if (expect_false (ev_is_active (w)))
1625 return; 1635 return;
1626 1636
1627 ev_start (EV_A_ (W)w, 1); 1637 ev_start (EV_A_ (W)w, 1);
1628 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1638 wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1629} 1639}
1630 1640
1631void 1641void
1632ev_child_stop (EV_P_ ev_child *w) 1642ev_child_stop (EV_P_ ev_child *w)
1633{ 1643{
1634 ev_clear_pending (EV_A_ (W)w); 1644 ev_clear_pending (EV_A_ (W)w);
1635 if (expect_false (!ev_is_active (w))) 1645 if (expect_false (!ev_is_active (w)))
1636 return; 1646 return;
1637 1647
1638 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1648 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1639 ev_stop (EV_A_ (W)w); 1649 ev_stop (EV_A_ (W)w);
1640} 1650}
1641 1651
1642#if EV_STAT_ENABLE 1652#if EV_STAT_ENABLE
1643 1653

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines