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

Comparing libev/ev.c (file contents):
Revision 1.256 by root, Thu Jun 19 06:53:49 2008 UTC vs.
Revision 1.264 by root, Mon Oct 13 23:20:12 2008 UTC

286# include <sys/select.h> 286# include <sys/select.h>
287# endif 287# endif
288#endif 288#endif
289 289
290#if EV_USE_INOTIFY 290#if EV_USE_INOTIFY
291# include <sys/utsname.h>
291# include <sys/inotify.h> 292# include <sys/inotify.h>
293/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
294# ifndef IN_DONT_FOLLOW
295# undef EV_USE_INOTIFY
296# define EV_USE_INOTIFY 0
297# endif
292#endif 298#endif
293 299
294#if EV_SELECT_IS_WINSOCKET 300#if EV_SELECT_IS_WINSOCKET
295# include <winsock.h> 301# include <winsock.h>
296#endif 302#endif
565 struct timeval tv; 571 struct timeval tv;
566 572
567 tv.tv_sec = (time_t)delay; 573 tv.tv_sec = (time_t)delay;
568 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); 574 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6);
569 575
576 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
577 /* somehting nto guaranteed by newer posix versions, but guaranteed */
578 /* by older ones */
570 select (0, 0, 0, 0, &tv); 579 select (0, 0, 0, 0, &tv);
571#endif 580#endif
572 } 581 }
573} 582}
574 583
1508{ 1517{
1509 postfork = 1; /* must be in line with ev_default_fork */ 1518 postfork = 1; /* must be in line with ev_default_fork */
1510} 1519}
1511 1520
1512#if EV_VERIFY 1521#if EV_VERIFY
1513void noinline 1522static void noinline
1514verify_watcher (EV_P_ W w) 1523verify_watcher (EV_P_ W w)
1515{ 1524{
1516 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 1525 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
1517 1526
1518 if (w->pending) 1527 if (w->pending)
1906ev_unref (EV_P) 1915ev_unref (EV_P)
1907{ 1916{
1908 --activecnt; 1917 --activecnt;
1909} 1918}
1910 1919
1920void
1921ev_now_update (EV_P)
1922{
1923 time_update (EV_A_ 1e100);
1924}
1925
1911static int loop_done; 1926static int loop_done;
1912 1927
1913void 1928void
1914ev_loop (EV_P_ int flags) 1929ev_loop (EV_P_ int flags)
1915{ 1930{
2482 2497
2483static void noinline 2498static void noinline
2484infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 2499infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
2485{ 2500{
2486 if (slot < 0) 2501 if (slot < 0)
2487 /* overflow, need to check for all hahs slots */ 2502 /* overflow, need to check for all hash slots */
2488 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 2503 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot)
2489 infy_wd (EV_A_ slot, wd, ev); 2504 infy_wd (EV_A_ slot, wd, ev);
2490 else 2505 else
2491 { 2506 {
2492 WL w_; 2507 WL w_;
2526infy_init (EV_P) 2541infy_init (EV_P)
2527{ 2542{
2528 if (fs_fd != -2) 2543 if (fs_fd != -2)
2529 return; 2544 return;
2530 2545
2546 /* kernels < 2.6.25 are borked
2547 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
2548 */
2549 {
2550 struct utsname buf;
2551 int major, minor, micro;
2552
2553 fs_fd = -1;
2554
2555 if (uname (&buf))
2556 return;
2557
2558 if (sscanf (buf.release, "%d.%d.%d", &major, &minor, &micro) != 3)
2559 return;
2560
2561 if (major < 2
2562 || (major == 2 && minor < 6)
2563 || (major == 2 && minor == 6 && micro < 25))
2564 return;
2565 }
2566
2531 fs_fd = inotify_init (); 2567 fs_fd = inotify_init ();
2532 2568
2533 if (fs_fd >= 0) 2569 if (fs_fd >= 0)
2534 { 2570 {
2535 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); 2571 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ);
2564 if (fs_fd >= 0) 2600 if (fs_fd >= 0)
2565 infy_add (EV_A_ w); /* re-add, no matter what */ 2601 infy_add (EV_A_ w); /* re-add, no matter what */
2566 else 2602 else
2567 ev_timer_start (EV_A_ &w->timer); 2603 ev_timer_start (EV_A_ &w->timer);
2568 } 2604 }
2569
2570 } 2605 }
2571} 2606}
2572 2607
2573#endif 2608#endif
2574 2609
2610 || w->prev.st_atime != w->attr.st_atime 2645 || w->prev.st_atime != w->attr.st_atime
2611 || w->prev.st_mtime != w->attr.st_mtime 2646 || w->prev.st_mtime != w->attr.st_mtime
2612 || w->prev.st_ctime != w->attr.st_ctime 2647 || w->prev.st_ctime != w->attr.st_ctime
2613 ) { 2648 ) {
2614 #if EV_USE_INOTIFY 2649 #if EV_USE_INOTIFY
2650 if (fs_fd >= 0)
2651 {
2615 infy_del (EV_A_ w); 2652 infy_del (EV_A_ w);
2616 infy_add (EV_A_ w); 2653 infy_add (EV_A_ w);
2617 ev_stat_stat (EV_A_ w); /* avoid race... */ 2654 ev_stat_stat (EV_A_ w); /* avoid race... */
2655 }
2618 #endif 2656 #endif
2619 2657
2620 ev_feed_event (EV_A_ w, EV_STAT); 2658 ev_feed_event (EV_A_ w, EV_STAT);
2621 } 2659 }
2622} 2660}
2824 ev_loop (EV_A_ EVLOOP_NONBLOCK); 2862 ev_loop (EV_A_ EVLOOP_NONBLOCK);
2825 } 2863 }
2826 } 2864 }
2827} 2865}
2828 2866
2867static void
2868embed_fork_cb (EV_P_ ev_fork *fork_w, int revents)
2869{
2870 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork));
2871
2872 {
2873 struct ev_loop *loop = w->other;
2874
2875 ev_loop_fork (EV_A);
2876 }
2877}
2878
2829#if 0 2879#if 0
2830static void 2880static void
2831embed_idle_cb (EV_P_ ev_idle *idle, int revents) 2881embed_idle_cb (EV_P_ ev_idle *idle, int revents)
2832{ 2882{
2833 ev_idle_stop (EV_A_ idle); 2883 ev_idle_stop (EV_A_ idle);
2853 2903
2854 ev_prepare_init (&w->prepare, embed_prepare_cb); 2904 ev_prepare_init (&w->prepare, embed_prepare_cb);
2855 ev_set_priority (&w->prepare, EV_MINPRI); 2905 ev_set_priority (&w->prepare, EV_MINPRI);
2856 ev_prepare_start (EV_A_ &w->prepare); 2906 ev_prepare_start (EV_A_ &w->prepare);
2857 2907
2908 ev_fork_init (&w->fork, embed_fork_cb);
2909 ev_fork_start (EV_A_ &w->fork);
2910
2858 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ 2911 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/
2859 2912
2860 ev_start (EV_A_ (W)w, 1); 2913 ev_start (EV_A_ (W)w, 1);
2861 2914
2862 EV_FREQUENT_CHECK; 2915 EV_FREQUENT_CHECK;
2869 if (expect_false (!ev_is_active (w))) 2922 if (expect_false (!ev_is_active (w)))
2870 return; 2923 return;
2871 2924
2872 EV_FREQUENT_CHECK; 2925 EV_FREQUENT_CHECK;
2873 2926
2874 ev_io_stop (EV_A_ &w->io); 2927 ev_io_stop (EV_A_ &w->io);
2875 ev_prepare_stop (EV_A_ &w->prepare); 2928 ev_prepare_stop (EV_A_ &w->prepare);
2876 2929 ev_fork_stop (EV_A_ &w->fork);
2877 ev_stop (EV_A_ (W)w);
2878 2930
2879 EV_FREQUENT_CHECK; 2931 EV_FREQUENT_CHECK;
2880} 2932}
2881#endif 2933#endif
2882 2934
2979once_cb (EV_P_ struct ev_once *once, int revents) 3031once_cb (EV_P_ struct ev_once *once, int revents)
2980{ 3032{
2981 void (*cb)(int revents, void *arg) = once->cb; 3033 void (*cb)(int revents, void *arg) = once->cb;
2982 void *arg = once->arg; 3034 void *arg = once->arg;
2983 3035
2984 ev_io_stop (EV_A_ &once->io); 3036 ev_io_stop (EV_A_ &once->io);
2985 ev_timer_stop (EV_A_ &once->to); 3037 ev_timer_stop (EV_A_ &once->to);
2986 ev_free (once); 3038 ev_free (once);
2987 3039
2988 cb (revents, arg); 3040 cb (revents, arg);
2989} 3041}
2990 3042
2991static void 3043static void
2992once_cb_io (EV_P_ ev_io *w, int revents) 3044once_cb_io (EV_P_ ev_io *w, int revents)
2993{ 3045{
2994 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); 3046 struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io));
3047
3048 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->to));
2995} 3049}
2996 3050
2997static void 3051static void
2998once_cb_to (EV_P_ ev_timer *w, int revents) 3052once_cb_to (EV_P_ ev_timer *w, int revents)
2999{ 3053{
3000 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); 3054 struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to));
3055
3056 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
3001} 3057}
3002 3058
3003void 3059void
3004ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 3060ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
3005{ 3061{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines