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

Comparing libev/ev.c (file contents):
Revision 1.130 by root, Fri Nov 23 05:13:48 2007 UTC vs.
Revision 1.134 by root, Fri Nov 23 19:13:33 2007 UTC

32#ifdef __cplusplus 32#ifdef __cplusplus
33extern "C" { 33extern "C" {
34#endif 34#endif
35 35
36#ifndef EV_STANDALONE 36#ifndef EV_STANDALONE
37# ifdef EV_CONFIG_H
38# include EV_CONFIG_H
39# else
37# include "config.h" 40# include "config.h"
41# endif
38 42
39# if HAVE_CLOCK_GETTIME 43# if HAVE_CLOCK_GETTIME
40# ifndef EV_USE_MONOTONIC 44# ifndef EV_USE_MONOTONIC
41# define EV_USE_MONOTONIC 1 45# define EV_USE_MONOTONIC 1
42# endif 46# endif
393 { 397 {
394 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 398 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
395 return; 399 return;
396 } 400 }
397 401
402 if (expect_false (!w_->cb))
403 return;
404
398 w_->pending = ++pendingcnt [ABSPRI (w_)]; 405 w_->pending = ++pendingcnt [ABSPRI (w_)];
399 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); 406 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
400 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 407 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
401 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 408 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
402} 409}
727 int pid, status; 734 int pid, status;
728 735
729 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 736 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
730 { 737 {
731 /* make sure we are called again until all childs have been reaped */ 738 /* make sure we are called again until all childs have been reaped */
739 /* we need to do it this way so that the callback gets called before we continue */
732 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 740 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
733 741
734 child_reap (EV_A_ sw, pid, pid, status); 742 child_reap (EV_A_ sw, pid, pid, status);
735 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 743 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
736 } 744 }
737} 745}
738 746
739#endif 747#endif
740 748
795} 803}
796 804
797unsigned int 805unsigned int
798ev_recommended_backends (void) 806ev_recommended_backends (void)
799{ 807{
800 unsigned int flags = ev_recommended_backends (); 808 unsigned int flags = ev_supported_backends ();
801 809
802#ifndef __NetBSD__ 810#ifndef __NetBSD__
803 /* kqueue is borked on everything but netbsd apparently */ 811 /* kqueue is borked on everything but netbsd apparently */
804 /* it usually doesn't work correctly on anything but sockets and pipes */ 812 /* it usually doesn't work correctly on anything but sockets and pipes */
805 flags &= ~EVBACKEND_KQUEUE; 813 flags &= ~EVBACKEND_KQUEUE;
808 // flags &= ~EVBACKEND_KQUEUE; for documentation 816 // flags &= ~EVBACKEND_KQUEUE; for documentation
809 flags &= ~EVBACKEND_POLL; 817 flags &= ~EVBACKEND_POLL;
810#endif 818#endif
811 819
812 return flags; 820 return flags;
821}
822
823unsigned int
824ev_embeddable_backends (void)
825{
826 return EVBACKEND_EPOLL
827 | EVBACKEND_KQUEUE
828 | EVBACKEND_PORT;
813} 829}
814 830
815unsigned int 831unsigned int
816ev_backend (EV_P) 832ev_backend (EV_P)
817{ 833{
1654 1670
1655 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1671 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1656 ev_stop (EV_A_ (W)w); 1672 ev_stop (EV_A_ (W)w);
1657} 1673}
1658 1674
1675#if EV_MULTIPLICITY
1676static void
1677embed_cb (EV_P_ struct ev_io *io, int revents)
1678{
1679 struct ev_embed *w = (struct ev_embed *)(((char *)io) - offsetof (struct ev_embed, io));
1680
1681 ev_feed_event (EV_A_ (W)w, EV_EMBED);
1682 ev_loop (w->loop, EVLOOP_NONBLOCK);
1683}
1684
1685void
1686ev_embed_start (EV_P_ struct ev_embed *w)
1687{
1688 if (expect_false (ev_is_active (w)))
1689 return;
1690
1691 {
1692 struct ev_loop *loop = w->loop;
1693 assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
1694 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
1695 }
1696
1697 ev_io_start (EV_A_ &w->io);
1698 ev_start (EV_A_ (W)w, 1);
1699}
1700
1701void
1702ev_embed_stop (EV_P_ struct ev_embed *w)
1703{
1704 ev_clear_pending (EV_A_ (W)w);
1705 if (expect_false (!ev_is_active (w)))
1706 return;
1707
1708 ev_io_stop (EV_A_ &w->io);
1709 ev_stop (EV_A_ (W)w);
1710}
1711#endif
1712
1659/*****************************************************************************/ 1713/*****************************************************************************/
1660 1714
1661struct ev_once 1715struct ev_once
1662{ 1716{
1663 struct ev_io io; 1717 struct ev_io io;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines