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

Comparing libev/ev.c (file contents):
Revision 1.318 by root, Tue Nov 17 00:22:28 2009 UTC vs.
Revision 1.325 by root, Sun Jan 24 12:31:55 2010 UTC

110# define EV_USE_EPOLL 0 110# define EV_USE_EPOLL 0
111# endif 111# endif
112# endif 112# endif
113 113
114# ifndef EV_USE_KQUEUE 114# ifndef EV_USE_KQUEUE
115# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H 115# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
116# define EV_USE_KQUEUE 1 116# define EV_USE_KQUEUE 1
117# else 117# else
118# define EV_USE_KQUEUE 0 118# define EV_USE_KQUEUE 0
119# endif 119# endif
120# endif 120# endif
153 153
154#endif 154#endif
155 155
156#include <math.h> 156#include <math.h>
157#include <stdlib.h> 157#include <stdlib.h>
158#include <string.h>
158#include <fcntl.h> 159#include <fcntl.h>
159#include <stddef.h> 160#include <stddef.h>
160 161
161#include <stdio.h> 162#include <stdio.h>
162 163
343# endif 344# endif
344#endif 345#endif
345 346
346/* this block fixes any misconfiguration where we know we run into trouble otherwise */ 347/* this block fixes any misconfiguration where we know we run into trouble otherwise */
347 348
349#ifdef _AIX
350/* AIX has a completely broken poll.h header */
351# undef EV_USE_POLL
352# define EV_USE_POLL 0
353#endif
354
348#ifndef CLOCK_MONOTONIC 355#ifndef CLOCK_MONOTONIC
349# undef EV_USE_MONOTONIC 356# undef EV_USE_MONOTONIC
350# define EV_USE_MONOTONIC 0 357# define EV_USE_MONOTONIC 0
351#endif 358#endif
352 359
504 511
505#ifndef EV_FD_TO_WIN32_HANDLE 512#ifndef EV_FD_TO_WIN32_HANDLE
506# define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) 513# define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd)
507#endif 514#endif
508#ifndef EV_WIN32_HANDLE_TO_FD 515#ifndef EV_WIN32_HANDLE_TO_FD
509# define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (fd, 0) 516# define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0)
510#endif 517#endif
511#ifndef EV_WIN32_CLOSE_FD 518#ifndef EV_WIN32_CLOSE_FD
512# define EV_WIN32_CLOSE_FD(fd) close (fd) 519# define EV_WIN32_CLOSE_FD(fd) close (fd)
513#endif 520#endif
514 521
963/* check whether the given fd is atcually valid, for error recovery */ 970/* check whether the given fd is atcually valid, for error recovery */
964inline_size int 971inline_size int
965fd_valid (int fd) 972fd_valid (int fd)
966{ 973{
967#ifdef _WIN32 974#ifdef _WIN32
968 return _get_osfhandle (fd) != -1; 975 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
969#else 976#else
970 return fcntl (fd, F_GETFD) != -1; 977 return fcntl (fd, F_GETFD) != -1;
971#endif 978#endif
972} 979}
973 980
1178inline_speed void 1185inline_speed void
1179fd_intern (int fd) 1186fd_intern (int fd)
1180{ 1187{
1181#ifdef _WIN32 1188#ifdef _WIN32
1182 unsigned long arg = 1; 1189 unsigned long arg = 1;
1183 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 1190 ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg);
1184#else 1191#else
1185 fcntl (fd, F_SETFD, FD_CLOEXEC); 1192 fcntl (fd, F_SETFD, FD_CLOEXEC);
1186 fcntl (fd, F_SETFL, O_NONBLOCK); 1193 fcntl (fd, F_SETFL, O_NONBLOCK);
1187#endif 1194#endif
1188} 1195}
1293{ 1300{
1294#if EV_MULTIPLICITY 1301#if EV_MULTIPLICITY
1295 EV_P = signals [signum - 1].loop; 1302 EV_P = signals [signum - 1].loop;
1296#endif 1303#endif
1297 1304
1298#if _WIN32 1305#ifdef _WIN32
1299 signal (signum, ev_sighandler); 1306 signal (signum, ev_sighandler);
1300#endif 1307#endif
1301 1308
1302 signals [signum - 1].pending = 1; 1309 signals [signum - 1].pending = 1;
1303 evpipe_write (EV_A_ &sig_pending); 1310 evpipe_write (EV_A_ &sig_pending);
1604#endif 1611#endif
1605#if EV_USE_INOTIFY 1612#if EV_USE_INOTIFY
1606 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 1613 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1607#endif 1614#endif
1608#if EV_USE_SIGNALFD 1615#if EV_USE_SIGNALFD
1609 sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2; 1616 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1610#endif 1617#endif
1611 1618
1612 if (!(flags & 0x0000ffffU)) 1619 if (!(flags & 0x0000ffffU))
1613 flags |= ev_recommended_backends (); 1620 flags |= ev_recommended_backends ();
1614 1621
2156 ANHE_at_cache (*he); 2163 ANHE_at_cache (*he);
2157 } 2164 }
2158} 2165}
2159 2166
2160/* fetch new monotonic and realtime times from the kernel */ 2167/* fetch new monotonic and realtime times from the kernel */
2161/* also detetc if there was a timejump, and act accordingly */ 2168/* also detect if there was a timejump, and act accordingly */
2162inline_speed void 2169inline_speed void
2163time_update (EV_P_ ev_tstamp max_block) 2170time_update (EV_P_ ev_tstamp max_block)
2164{ 2171{
2165#if EV_USE_MONOTONIC 2172#if EV_USE_MONOTONIC
2166 if (expect_true (have_monotonic)) 2173 if (expect_true (have_monotonic))
2746 if (!((WL)w)->next) 2753 if (!((WL)w)->next)
2747# if EV_USE_SIGNALFD 2754# if EV_USE_SIGNALFD
2748 if (sigfd < 0) /*TODO*/ 2755 if (sigfd < 0) /*TODO*/
2749# endif 2756# endif
2750 { 2757 {
2751# if _WIN32 2758# ifdef _WIN32
2752 evpipe_init (EV_A); 2759 evpipe_init (EV_A);
2753 2760
2754 signal (w->signum, ev_sighandler); 2761 signal (w->signum, ev_sighandler);
2755# else 2762# else
2756 struct sigaction sa; 2763 struct sigaction sa;
2789 signals [w->signum - 1].loop = 0; /* unattach from signal */ 2796 signals [w->signum - 1].loop = 0; /* unattach from signal */
2790#endif 2797#endif
2791#if EV_USE_SIGNALFD 2798#if EV_USE_SIGNALFD
2792 if (sigfd >= 0) 2799 if (sigfd >= 0)
2793 { 2800 {
2794 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D 2801 sigset_t ss;
2802
2803 sigemptyset (&ss);
2804 sigaddset (&ss, w->signum);
2795 sigdelset (&sigfd_set, w->signum); 2805 sigdelset (&sigfd_set, w->signum);
2806
2796 signalfd (sigfd, &sigfd_set, 0); 2807 signalfd (sigfd, &sigfd_set, 0);
2797 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D 2808 sigprocmask (SIG_UNBLOCK, &ss, 0);
2798 /*TODO: maybe unblock signal? */
2799 } 2809 }
2800 else 2810 else
2801#endif 2811#endif
2802 signal (w->signum, SIG_DFL); 2812 signal (w->signum, SIG_DFL);
2803 } 2813 }
3100static void noinline 3110static void noinline
3101stat_timer_cb (EV_P_ ev_timer *w_, int revents) 3111stat_timer_cb (EV_P_ ev_timer *w_, int revents)
3102{ 3112{
3103 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 3113 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
3104 3114
3105 /* we copy this here each the time so that */ 3115 ev_statdata prev = w->attr;
3106 /* prev has the old value when the callback gets invoked */
3107 w->prev = w->attr;
3108 ev_stat_stat (EV_A_ w); 3116 ev_stat_stat (EV_A_ w);
3109 3117
3110 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */ 3118 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */
3111 if ( 3119 if (
3112 w->prev.st_dev != w->attr.st_dev 3120 prev.st_dev != w->attr.st_dev
3113 || w->prev.st_ino != w->attr.st_ino 3121 || prev.st_ino != w->attr.st_ino
3114 || w->prev.st_mode != w->attr.st_mode 3122 || prev.st_mode != w->attr.st_mode
3115 || w->prev.st_nlink != w->attr.st_nlink 3123 || prev.st_nlink != w->attr.st_nlink
3116 || w->prev.st_uid != w->attr.st_uid 3124 || prev.st_uid != w->attr.st_uid
3117 || w->prev.st_gid != w->attr.st_gid 3125 || prev.st_gid != w->attr.st_gid
3118 || w->prev.st_rdev != w->attr.st_rdev 3126 || prev.st_rdev != w->attr.st_rdev
3119 || w->prev.st_size != w->attr.st_size 3127 || prev.st_size != w->attr.st_size
3120 || w->prev.st_atime != w->attr.st_atime 3128 || prev.st_atime != w->attr.st_atime
3121 || w->prev.st_mtime != w->attr.st_mtime 3129 || prev.st_mtime != w->attr.st_mtime
3122 || w->prev.st_ctime != w->attr.st_ctime 3130 || prev.st_ctime != w->attr.st_ctime
3123 ) { 3131 ) {
3132 /* we only update w->prev on actual differences */
3133 /* in case we test more often than invoke the callback, */
3134 /* to ensure that prev is always different to attr */
3135 w->prev = prev;
3136
3124 #if EV_USE_INOTIFY 3137 #if EV_USE_INOTIFY
3125 if (fs_fd >= 0) 3138 if (fs_fd >= 0)
3126 { 3139 {
3127 infy_del (EV_A_ w); 3140 infy_del (EV_A_ w);
3128 infy_add (EV_A_ w); 3141 infy_add (EV_A_ w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines