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

Comparing libev/ev.c (file contents):
Revision 1.146 by root, Tue Nov 27 09:17:51 2007 UTC vs.
Revision 1.149 by root, Tue Nov 27 19:23:31 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
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/*****************************************************************************/
1276 ? EVUNLOOP_ONE 1284 ? EVUNLOOP_ONE
1277 : EVUNLOOP_CANCEL; 1285 : EVUNLOOP_CANCEL;
1278 1286
1279 while (activecnt) 1287 while (activecnt)
1280 { 1288 {
1289 /* we might have forked, so reify kernel state if necessary */
1290 #if EV_FORK_ENABLE
1291 if (expect_false (postfork))
1292 if (forkcnt)
1293 {
1294 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1295 call_pending (EV_A);
1296 }
1297 #endif
1298
1281 /* queue check watchers (and execute them) */ 1299 /* queue check watchers (and execute them) */
1282 if (expect_false (preparecnt)) 1300 if (expect_false (preparecnt))
1283 { 1301 {
1284 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1302 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1285 call_pending (EV_A); 1303 call_pending (EV_A);
1615#endif 1633#endif
1616 if (expect_false (ev_is_active (w))) 1634 if (expect_false (ev_is_active (w)))
1617 return; 1635 return;
1618 1636
1619 ev_start (EV_A_ (W)w, 1); 1637 ev_start (EV_A_ (W)w, 1);
1620 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1638 wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1621} 1639}
1622 1640
1623void 1641void
1624ev_child_stop (EV_P_ ev_child *w) 1642ev_child_stop (EV_P_ ev_child *w)
1625{ 1643{
1626 ev_clear_pending (EV_A_ (W)w); 1644 ev_clear_pending (EV_A_ (W)w);
1627 if (expect_false (!ev_is_active (w))) 1645 if (expect_false (!ev_is_active (w)))
1628 return; 1646 return;
1629 1647
1630 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1648 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1631 ev_stop (EV_A_ (W)w); 1649 ev_stop (EV_A_ (W)w);
1632} 1650}
1633 1651
1634#if EV_STAT_ENABLE 1652#if EV_STAT_ENABLE
1635 1653
1827 1845
1828 ev_stop (EV_A_ (W)w); 1846 ev_stop (EV_A_ (W)w);
1829} 1847}
1830#endif 1848#endif
1831 1849
1850#if EV_FORK_ENABLE
1851void
1852ev_fork_start (EV_P_ ev_fork *w)
1853{
1854 if (expect_false (ev_is_active (w)))
1855 return;
1856
1857 ev_start (EV_A_ (W)w, ++forkcnt);
1858 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2);
1859 forks [forkcnt - 1] = w;
1860}
1861
1862void
1863ev_fork_stop (EV_P_ ev_fork *w)
1864{
1865 ev_clear_pending (EV_A_ (W)w);
1866 if (expect_false (!ev_is_active (w)))
1867 return;
1868
1869 {
1870 int active = ((W)w)->active;
1871 forks [active - 1] = forks [--forkcnt];
1872 ((W)forks [active - 1])->active = active;
1873 }
1874
1875 ev_stop (EV_A_ (W)w);
1876}
1877#endif
1878
1832/*****************************************************************************/ 1879/*****************************************************************************/
1833 1880
1834struct ev_once 1881struct ev_once
1835{ 1882{
1836 ev_io io; 1883 ev_io io;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines