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

Comparing libev/ev.c (file contents):
Revision 1.117 by ayin, Thu Nov 15 17:15:56 2007 UTC vs.
Revision 1.122 by root, Sat Nov 17 02:00:48 2007 UTC

59 59
60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) 60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE)
61# define EV_USE_KQUEUE 1 61# define EV_USE_KQUEUE 1
62# endif 62# endif
63 63
64# if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT)
65# define EV_USE_PORT 1
66# endif
67
64#endif 68#endif
65 69
66#include <math.h> 70#include <math.h>
67#include <stdlib.h> 71#include <stdlib.h>
68#include <fcntl.h> 72#include <fcntl.h>
90#endif 94#endif
91 95
92/**/ 96/**/
93 97
94#ifndef EV_USE_MONOTONIC 98#ifndef EV_USE_MONOTONIC
95# define EV_USE_MONOTONIC 1 99# define EV_USE_MONOTONIC 0
100#endif
101
102#ifndef EV_USE_REALTIME
103# define EV_USE_REALTIME 0
96#endif 104#endif
97 105
98#ifndef EV_USE_SELECT 106#ifndef EV_USE_SELECT
99# define EV_USE_SELECT 1 107# define EV_USE_SELECT 1
100# define EV_SELECT_USE_FD_SET 1
101#endif 108#endif
102 109
103#ifndef EV_USE_POLL 110#ifndef EV_USE_POLL
104# ifdef _WIN32 111# ifdef _WIN32
105# define EV_USE_POLL 0 112# define EV_USE_POLL 0
114 121
115#ifndef EV_USE_KQUEUE 122#ifndef EV_USE_KQUEUE
116# define EV_USE_KQUEUE 0 123# define EV_USE_KQUEUE 0
117#endif 124#endif
118 125
119#ifndef EV_USE_REALTIME 126#ifndef EV_USE_PORT
120# define EV_USE_REALTIME 1 127# define EV_USE_PORT 0
121#endif 128#endif
122 129
123/**/ 130/**/
124 131
125/* darwin simply cannot be helped */ 132/* darwin simply cannot be helped */
143#endif 150#endif
144 151
145/**/ 152/**/
146 153
147#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 154#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
148#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 155#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
149#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 156#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
150/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 157/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
151 158
152#ifdef EV_H 159#ifdef EV_H
153# include EV_H 160# include EV_H
154#else 161#else
155# include "ev.h" 162# include "ev.h"
710 717
711#endif 718#endif
712 719
713/*****************************************************************************/ 720/*****************************************************************************/
714 721
722#if EV_USE_PORT
723# include "ev_port.c"
724#endif
715#if EV_USE_KQUEUE 725#if EV_USE_KQUEUE
716# include "ev_kqueue.c" 726# include "ev_kqueue.c"
717#endif 727#endif
718#if EV_USE_EPOLL 728#if EV_USE_EPOLL
719# include "ev_epoll.c" 729# include "ev_epoll.c"
778 788
779 if (!(flags & 0x0000ffff)) 789 if (!(flags & 0x0000ffff))
780 flags |= 0x0000ffff; 790 flags |= 0x0000ffff;
781 791
782 method = 0; 792 method = 0;
793#if EV_USE_PORT
794 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags);
795#endif
783#if EV_USE_KQUEUE 796#if EV_USE_KQUEUE
784 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 797 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
785#endif 798#endif
786#if EV_USE_EPOLL 799#if EV_USE_EPOLL
787 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 800 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
801void 814void
802loop_destroy (EV_P) 815loop_destroy (EV_P)
803{ 816{
804 int i; 817 int i;
805 818
819#if EV_USE_PORT
820 if (method == EVMETHOD_PORT ) port_destroy (EV_A);
821#endif
806#if EV_USE_KQUEUE 822#if EV_USE_KQUEUE
807 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 823 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
808#endif 824#endif
809#if EV_USE_EPOLL 825#if EV_USE_EPOLL
810 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 826 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
833} 849}
834 850
835static void 851static void
836loop_fork (EV_P) 852loop_fork (EV_P)
837{ 853{
854#if EV_USE_PORT
855 if (method == EVMETHOD_PORT ) port_fork (EV_A);
856#endif
857#if EV_USE_KQUEUE
858 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
859#endif
838#if EV_USE_EPOLL 860#if EV_USE_EPOLL
839 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 861 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
840#endif
841#if EV_USE_KQUEUE
842 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
843#endif 862#endif
844 863
845 if (ev_is_active (&sigev)) 864 if (ev_is_active (&sigev))
846 { 865 {
847 /* default loop */ 866 /* default loop */
975 return 1; 994 return 1;
976 995
977 return 0; 996 return 0;
978} 997}
979 998
980static void 999inline void
981call_pending (EV_P) 1000call_pending (EV_P)
982{ 1001{
983 int pri; 1002 int pri;
984 1003
985 for (pri = NUMPRI; pri--; ) 1004 for (pri = NUMPRI; pri--; )
986 while (pendingcnt [pri]) 1005 while (pendingcnt [pri])
987 { 1006 {
988 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1007 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
989 1008
990 if (p->w) 1009 if (expect_true (p->w))
991 { 1010 {
992 p->w->pending = 0; 1011 p->w->pending = 0;
993 EV_CB_INVOKE (p->w, p->events); 1012 EV_CB_INVOKE (p->w, p->events);
994 } 1013 }
995 } 1014 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines