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

Comparing libev/ev.c (file contents):
Revision 1.258 by root, Sun Sep 7 18:15:12 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
1909ev_unref (EV_P) 1915ev_unref (EV_P)
1910{ 1916{
1911 --activecnt; 1917 --activecnt;
1912} 1918}
1913 1919
1920void
1921ev_now_update (EV_P)
1922{
1923 time_update (EV_A_ 1e100);
1924}
1925
1914static int loop_done; 1926static int loop_done;
1915 1927
1916void 1928void
1917ev_loop (EV_P_ int flags) 1929ev_loop (EV_P_ int flags)
1918{ 1930{
2485 2497
2486static void noinline 2498static void noinline
2487infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 2499infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
2488{ 2500{
2489 if (slot < 0) 2501 if (slot < 0)
2490 /* overflow, need to check for all hahs slots */ 2502 /* overflow, need to check for all hash slots */
2491 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 2503 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot)
2492 infy_wd (EV_A_ slot, wd, ev); 2504 infy_wd (EV_A_ slot, wd, ev);
2493 else 2505 else
2494 { 2506 {
2495 WL w_; 2507 WL w_;
2529infy_init (EV_P) 2541infy_init (EV_P)
2530{ 2542{
2531 if (fs_fd != -2) 2543 if (fs_fd != -2)
2532 return; 2544 return;
2533 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
2534 fs_fd = inotify_init (); 2567 fs_fd = inotify_init ();
2535 2568
2536 if (fs_fd >= 0) 2569 if (fs_fd >= 0)
2537 { 2570 {
2538 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); 2571 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ);
2567 if (fs_fd >= 0) 2600 if (fs_fd >= 0)
2568 infy_add (EV_A_ w); /* re-add, no matter what */ 2601 infy_add (EV_A_ w); /* re-add, no matter what */
2569 else 2602 else
2570 ev_timer_start (EV_A_ &w->timer); 2603 ev_timer_start (EV_A_ &w->timer);
2571 } 2604 }
2572
2573 } 2605 }
2574} 2606}
2575 2607
2576#endif 2608#endif
2577 2609
2613 || w->prev.st_atime != w->attr.st_atime 2645 || w->prev.st_atime != w->attr.st_atime
2614 || w->prev.st_mtime != w->attr.st_mtime 2646 || w->prev.st_mtime != w->attr.st_mtime
2615 || w->prev.st_ctime != w->attr.st_ctime 2647 || w->prev.st_ctime != w->attr.st_ctime
2616 ) { 2648 ) {
2617 #if EV_USE_INOTIFY 2649 #if EV_USE_INOTIFY
2650 if (fs_fd >= 0)
2651 {
2618 infy_del (EV_A_ w); 2652 infy_del (EV_A_ w);
2619 infy_add (EV_A_ w); 2653 infy_add (EV_A_ w);
2620 ev_stat_stat (EV_A_ w); /* avoid race... */ 2654 ev_stat_stat (EV_A_ w); /* avoid race... */
2655 }
2621 #endif 2656 #endif
2622 2657
2623 ev_feed_event (EV_A_ w, EV_STAT); 2658 ev_feed_event (EV_A_ w, EV_STAT);
2624 } 2659 }
2625} 2660}
2827 ev_loop (EV_A_ EVLOOP_NONBLOCK); 2862 ev_loop (EV_A_ EVLOOP_NONBLOCK);
2828 } 2863 }
2829 } 2864 }
2830} 2865}
2831 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
2832#if 0 2879#if 0
2833static void 2880static void
2834embed_idle_cb (EV_P_ ev_idle *idle, int revents) 2881embed_idle_cb (EV_P_ ev_idle *idle, int revents)
2835{ 2882{
2836 ev_idle_stop (EV_A_ idle); 2883 ev_idle_stop (EV_A_ idle);
2856 2903
2857 ev_prepare_init (&w->prepare, embed_prepare_cb); 2904 ev_prepare_init (&w->prepare, embed_prepare_cb);
2858 ev_set_priority (&w->prepare, EV_MINPRI); 2905 ev_set_priority (&w->prepare, EV_MINPRI);
2859 ev_prepare_start (EV_A_ &w->prepare); 2906 ev_prepare_start (EV_A_ &w->prepare);
2860 2907
2908 ev_fork_init (&w->fork, embed_fork_cb);
2909 ev_fork_start (EV_A_ &w->fork);
2910
2861 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ 2911 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/
2862 2912
2863 ev_start (EV_A_ (W)w, 1); 2913 ev_start (EV_A_ (W)w, 1);
2864 2914
2865 EV_FREQUENT_CHECK; 2915 EV_FREQUENT_CHECK;
2872 if (expect_false (!ev_is_active (w))) 2922 if (expect_false (!ev_is_active (w)))
2873 return; 2923 return;
2874 2924
2875 EV_FREQUENT_CHECK; 2925 EV_FREQUENT_CHECK;
2876 2926
2877 ev_io_stop (EV_A_ &w->io); 2927 ev_io_stop (EV_A_ &w->io);
2878 ev_prepare_stop (EV_A_ &w->prepare); 2928 ev_prepare_stop (EV_A_ &w->prepare);
2879 2929 ev_fork_stop (EV_A_ &w->fork);
2880 ev_stop (EV_A_ (W)w);
2881 2930
2882 EV_FREQUENT_CHECK; 2931 EV_FREQUENT_CHECK;
2883} 2932}
2884#endif 2933#endif
2885 2934
2982once_cb (EV_P_ struct ev_once *once, int revents) 3031once_cb (EV_P_ struct ev_once *once, int revents)
2983{ 3032{
2984 void (*cb)(int revents, void *arg) = once->cb; 3033 void (*cb)(int revents, void *arg) = once->cb;
2985 void *arg = once->arg; 3034 void *arg = once->arg;
2986 3035
2987 ev_io_stop (EV_A_ &once->io); 3036 ev_io_stop (EV_A_ &once->io);
2988 ev_timer_stop (EV_A_ &once->to); 3037 ev_timer_stop (EV_A_ &once->to);
2989 ev_free (once); 3038 ev_free (once);
2990 3039
2991 cb (revents, arg); 3040 cb (revents, arg);
2992} 3041}
2993 3042
2994static void 3043static void
2995once_cb_io (EV_P_ ev_io *w, int revents) 3044once_cb_io (EV_P_ ev_io *w, int revents)
2996{ 3045{
2997 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));
2998} 3049}
2999 3050
3000static void 3051static void
3001once_cb_to (EV_P_ ev_timer *w, int revents) 3052once_cb_to (EV_P_ ev_timer *w, int revents)
3002{ 3053{
3003 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));
3004} 3057}
3005 3058
3006void 3059void
3007ev_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)
3008{ 3061{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines