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

Comparing libev/ev.c (file contents):
Revision 1.358 by root, Sun Oct 24 14:44:40 2010 UTC vs.
Revision 1.365 by root, Sun Oct 31 22:01:20 2010 UTC

530 530
531static unsigned int noinline 531static unsigned int noinline
532ev_linux_version (void) 532ev_linux_version (void)
533{ 533{
534#ifdef __linux 534#ifdef __linux
535 unsigned int v = 0;
535 struct utsname buf; 536 struct utsname buf;
536 unsigned int v;
537 int i; 537 int i;
538 char *p = buf.release; 538 char *p = buf.release;
539 539
540 if (uname (&buf)) 540 if (uname (&buf))
541 return 0; 541 return 0;
591 if (syserr_cb) 591 if (syserr_cb)
592 syserr_cb (msg); 592 syserr_cb (msg);
593 else 593 else
594 { 594 {
595#if EV_AVOID_STDIO 595#if EV_AVOID_STDIO
596 const char *err = strerror (errno);
597
598 ev_printerr (msg); 596 ev_printerr (msg);
599 ev_printerr (": "); 597 ev_printerr (": ");
600 ev_printerr (err); 598 ev_printerr (strerror (errno));
601 ev_printerr ("\n"); 599 ev_printerr ("\n");
602#else 600#else
603 perror (msg); 601 perror (msg);
604#endif 602#endif
605 abort (); 603 abort ();
639 ptr = alloc (ptr, size); 637 ptr = alloc (ptr, size);
640 638
641 if (!ptr && size) 639 if (!ptr && size)
642 { 640 {
643#if EV_AVOID_STDIO 641#if EV_AVOID_STDIO
644 ev_printerr ("libev: memory allocation failed, aborting.\n"); 642 ev_printerr ("(libev) memory allocation failed, aborting.\n");
645#else 643#else
646 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 644 fprintf (stderr, "(libev) cannot allocate %ld bytes, aborting.", size);
647#endif 645#endif
648 abort (); 646 abort ();
649 } 647 }
650 648
651 return ptr; 649 return ptr;
1731#endif 1729#endif
1732 } 1730 }
1733} 1731}
1734 1732
1735/* free up a loop structure */ 1733/* free up a loop structure */
1736static void noinline 1734void
1737loop_destroy (EV_P) 1735ev_loop_destroy (EV_P)
1738{ 1736{
1739 int i; 1737 int i;
1738
1739#if EV_MULTIPLICITY
1740 /* mimic free (0) */
1741 if (!EV_A)
1742 return;
1743#endif
1744
1745#if EV_CLEANUP_ENABLE
1746 /* queue cleanup watchers (and execute them) */
1747 if (expect_false (cleanupcnt))
1748 {
1749 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
1750 EV_INVOKE_PENDING;
1751 }
1752#endif
1753
1754#if EV_CHILD_ENABLE
1755 if (ev_is_active (&childev))
1756 {
1757 ev_ref (EV_A); /* child watcher */
1758 ev_signal_stop (EV_A_ &childev);
1759 }
1760#endif
1740 1761
1741 if (ev_is_active (&pipe_w)) 1762 if (ev_is_active (&pipe_w))
1742 { 1763 {
1743 /*ev_ref (EV_A);*/ 1764 /*ev_ref (EV_A);*/
1744 /*ev_io_stop (EV_A_ &pipe_w);*/ 1765 /*ev_io_stop (EV_A_ &pipe_w);*/
1805 array_free (periodic, EMPTY); 1826 array_free (periodic, EMPTY);
1806#endif 1827#endif
1807#if EV_FORK_ENABLE 1828#if EV_FORK_ENABLE
1808 array_free (fork, EMPTY); 1829 array_free (fork, EMPTY);
1809#endif 1830#endif
1831#if EV_CLEANUP_ENABLE
1832 array_free (cleanup, EMPTY);
1833#endif
1810 array_free (prepare, EMPTY); 1834 array_free (prepare, EMPTY);
1811 array_free (check, EMPTY); 1835 array_free (check, EMPTY);
1812#if EV_ASYNC_ENABLE 1836#if EV_ASYNC_ENABLE
1813 array_free (async, EMPTY); 1837 array_free (async, EMPTY);
1814#endif 1838#endif
1815 1839
1816 backend = 0; 1840 backend = 0;
1841
1842#if EV_MULTIPLICITY
1843 if (ev_is_default_loop (EV_A))
1844#endif
1845 ev_default_loop_ptr = 0;
1846#if EV_MULTIPLICITY
1847 else
1848 ev_free (EV_A);
1849#endif
1817} 1850}
1818 1851
1819#if EV_USE_INOTIFY 1852#if EV_USE_INOTIFY
1820inline_size void infy_fork (EV_P); 1853inline_size void infy_fork (EV_P);
1821#endif 1854#endif
1880 loop_init (EV_A_ flags); 1913 loop_init (EV_A_ flags);
1881 1914
1882 if (ev_backend (EV_A)) 1915 if (ev_backend (EV_A))
1883 return EV_A; 1916 return EV_A;
1884 1917
1918 ev_free (EV_A);
1885 return 0; 1919 return 0;
1886} 1920}
1887 1921
1888void
1889ev_loop_destroy (EV_P)
1890{
1891 loop_destroy (EV_A);
1892 ev_free (loop);
1893}
1894
1895void
1896ev_loop_fork (EV_P)
1897{
1898 postfork = 1; /* must be in line with ev_default_fork */
1899}
1900#endif /* multiplicity */ 1922#endif /* multiplicity */
1901 1923
1902#if EV_VERIFY 1924#if EV_VERIFY
1903static void noinline 1925static void noinline
1904verify_watcher (EV_P_ W w) 1926verify_watcher (EV_P_ W w)
1979#if EV_FORK_ENABLE 2001#if EV_FORK_ENABLE
1980 assert (forkmax >= forkcnt); 2002 assert (forkmax >= forkcnt);
1981 array_verify (EV_A_ (W *)forks, forkcnt); 2003 array_verify (EV_A_ (W *)forks, forkcnt);
1982#endif 2004#endif
1983 2005
2006#if EV_CLEANUP_ENABLE
2007 assert (cleanupmax >= cleanupcnt);
2008 array_verify (EV_A_ (W *)cleanups, cleanupcnt);
2009#endif
2010
1984#if EV_ASYNC_ENABLE 2011#if EV_ASYNC_ENABLE
1985 assert (asyncmax >= asynccnt); 2012 assert (asyncmax >= asynccnt);
1986 array_verify (EV_A_ (W *)asyncs, asynccnt); 2013 array_verify (EV_A_ (W *)asyncs, asynccnt);
1987#endif 2014#endif
1988 2015
2038 2065
2039 return ev_default_loop_ptr; 2066 return ev_default_loop_ptr;
2040} 2067}
2041 2068
2042void 2069void
2043ev_default_destroy (void) 2070ev_loop_fork (EV_P)
2044{ 2071{
2045#if EV_MULTIPLICITY
2046 EV_P = ev_default_loop_ptr;
2047#endif
2048
2049 ev_default_loop_ptr = 0;
2050
2051#if EV_CHILD_ENABLE
2052 ev_ref (EV_A); /* child watcher */
2053 ev_signal_stop (EV_A_ &childev);
2054#endif
2055
2056 loop_destroy (EV_A);
2057}
2058
2059void
2060ev_default_fork (void)
2061{
2062#if EV_MULTIPLICITY
2063 EV_P = ev_default_loop_ptr;
2064#endif
2065
2066 postfork = 1; /* must be in line with ev_loop_fork */ 2072 postfork = 1; /* must be in line with ev_default_fork */
2067} 2073}
2068 2074
2069/*****************************************************************************/ 2075/*****************************************************************************/
2070 2076
2071void 2077void
3577 3583
3578 EV_FREQUENT_CHECK; 3584 EV_FREQUENT_CHECK;
3579} 3585}
3580#endif 3586#endif
3581 3587
3588#if EV_CLEANUP_ENABLE
3589void
3590ev_cleanup_start (EV_P_ ev_cleanup *w)
3591{
3592 if (expect_false (ev_is_active (w)))
3593 return;
3594
3595 EV_FREQUENT_CHECK;
3596
3597 ev_start (EV_A_ (W)w, ++cleanupcnt);
3598 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2);
3599 cleanups [cleanupcnt - 1] = w;
3600
3601 /* cleanup watchers should never keep a refcount on the loop */
3602 ev_unref (EV_A);
3603 EV_FREQUENT_CHECK;
3604}
3605
3606void
3607ev_cleanup_stop (EV_P_ ev_cleanup *w)
3608{
3609 clear_pending (EV_A_ (W)w);
3610 if (expect_false (!ev_is_active (w)))
3611 return;
3612
3613 EV_FREQUENT_CHECK;
3614 ev_ref (EV_A);
3615
3616 {
3617 int active = ev_active (w);
3618
3619 cleanups [active - 1] = cleanups [--cleanupcnt];
3620 ev_active (cleanups [active - 1]) = active;
3621 }
3622
3623 ev_stop (EV_A_ (W)w);
3624
3625 EV_FREQUENT_CHECK;
3626}
3627#endif
3628
3582#if EV_ASYNC_ENABLE 3629#if EV_ASYNC_ENABLE
3583void 3630void
3584ev_async_start (EV_P_ ev_async *w) 3631ev_async_start (EV_P_ ev_async *w)
3585{ 3632{
3586 if (expect_false (ev_is_active (w))) 3633 if (expect_false (ev_is_active (w)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines