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

Comparing libev/ev.c (file contents):
Revision 1.315 by root, Wed Aug 26 17:46:22 2009 UTC vs.
Revision 1.318 by root, Tue Nov 17 00:22:28 2009 UTC

450 */ 450 */
451#define TIME_EPSILON 0.0001220703125 /* 1/8192 */ 451#define TIME_EPSILON 0.0001220703125 /* 1/8192 */
452 452
453#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 453#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
454#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 454#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
455/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */
456 455
457#if __GNUC__ >= 4 456#if __GNUC__ >= 4
458# define expect(expr,value) __builtin_expect ((expr),(value)) 457# define expect(expr,value) __builtin_expect ((expr),(value))
459# define noinline __attribute__ ((noinline)) 458# define noinline __attribute__ ((noinline))
460#else 459#else
1659 } 1658 }
1660 } 1659 }
1661 1660
1662#if EV_USE_SIGNALFD 1661#if EV_USE_SIGNALFD
1663 if (ev_is_active (&sigfd_w)) 1662 if (ev_is_active (&sigfd_w))
1664 {
1665 /*ev_ref (EV_A);*/
1666 /*ev_io_stop (EV_A_ &sigfd_w);*/
1667
1668 close (sigfd); 1663 close (sigfd);
1669 }
1670#endif 1664#endif
1671 1665
1672#if EV_USE_INOTIFY 1666#if EV_USE_INOTIFY
1673 if (fs_fd >= 0) 1667 if (fs_fd >= 0)
1674 close (fs_fd); 1668 close (fs_fd);
2753# if EV_USE_SIGNALFD 2747# if EV_USE_SIGNALFD
2754 if (sigfd < 0) /*TODO*/ 2748 if (sigfd < 0) /*TODO*/
2755# endif 2749# endif
2756 { 2750 {
2757# if _WIN32 2751# if _WIN32
2752 evpipe_init (EV_A);
2753
2758 signal (w->signum, ev_sighandler); 2754 signal (w->signum, ev_sighandler);
2759# else 2755# else
2760 struct sigaction sa; 2756 struct sigaction sa;
2761 2757
2762 evpipe_init (EV_A); 2758 evpipe_init (EV_A);
2860static void noinline 2856static void noinline
2861infy_add (EV_P_ ev_stat *w) 2857infy_add (EV_P_ ev_stat *w)
2862{ 2858{
2863 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); 2859 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD);
2864 2860
2865 if (w->wd < 0) 2861 if (w->wd >= 0)
2862 {
2863 struct statfs sfs;
2864
2865 /* now local changes will be tracked by inotify, but remote changes won't */
2866 /* unless the filesystem is known to be local, we therefore still poll */
2867 /* also do poll on <2.6.25, but with normal frequency */
2868
2869 if (!fs_2625)
2870 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
2871 else if (!statfs (w->path, &sfs)
2872 && (sfs.f_type == 0x1373 /* devfs */
2873 || sfs.f_type == 0xEF53 /* ext2/3 */
2874 || sfs.f_type == 0x3153464a /* jfs */
2875 || sfs.f_type == 0x52654973 /* reiser3 */
2876 || sfs.f_type == 0x01021994 /* tempfs */
2877 || sfs.f_type == 0x58465342 /* xfs */))
2878 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */
2879 else
2880 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */
2866 { 2881 }
2882 else
2883 {
2884 /* can't use inotify, continue to stat */
2867 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; 2885 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
2868 ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2869 2886
2870 /* monitor some parent directory for speedup hints */ 2887 /* if path is not there, monitor some parent directory for speedup hints */
2871 /* note that exceeding the hardcoded path limit is not a correctness issue, */ 2888 /* note that exceeding the hardcoded path limit is not a correctness issue, */
2872 /* but an efficiency issue only */ 2889 /* but an efficiency issue only */
2873 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2890 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2874 { 2891 {
2875 char path [4096]; 2892 char path [4096];
2891 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 2908 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
2892 } 2909 }
2893 } 2910 }
2894 2911
2895 if (w->wd >= 0) 2912 if (w->wd >= 0)
2896 {
2897 struct statfs sfs;
2898
2899 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 2913 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w);
2900 2914
2901 /* now local changes will be tracked by inotify, but remote changes won't */ 2915 /* now re-arm timer, if required */
2902 /* unless the filesystem it known to be local, we therefore still poll */ 2916 if (ev_is_active (&w->timer)) ev_ref (EV_A);
2903 /* also do poll on <2.6.25, but with normal frequency */
2904
2905 if (fs_2625 && !statfs (w->path, &sfs))
2906 if (sfs.f_type == 0x1373 /* devfs */
2907 || sfs.f_type == 0xEF53 /* ext2/3 */
2908 || sfs.f_type == 0x3153464a /* jfs */
2909 || sfs.f_type == 0x52654973 /* reiser3 */
2910 || sfs.f_type == 0x01021994 /* tempfs */
2911 || sfs.f_type == 0x58465342 /* xfs */)
2912 return;
2913
2914 w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL;
2915 ev_timer_again (EV_A_ &w->timer); 2917 ev_timer_again (EV_A_ &w->timer);
2916 } 2918 if (ev_is_active (&w->timer)) ev_unref (EV_A);
2917} 2919}
2918 2920
2919static void noinline 2921static void noinline
2920infy_del (EV_P_ ev_stat *w) 2922infy_del (EV_P_ ev_stat *w)
2921{ 2923{
3026 { 3028 {
3027 fd_intern (fs_fd); 3029 fd_intern (fs_fd);
3028 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); 3030 ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ);
3029 ev_set_priority (&fs_w, EV_MAXPRI); 3031 ev_set_priority (&fs_w, EV_MAXPRI);
3030 ev_io_start (EV_A_ &fs_w); 3032 ev_io_start (EV_A_ &fs_w);
3033 ev_unref (EV_A);
3031 } 3034 }
3032} 3035}
3033 3036
3034inline_size void 3037inline_size void
3035infy_fork (EV_P) 3038infy_fork (EV_P)
3037 int slot; 3040 int slot;
3038 3041
3039 if (fs_fd < 0) 3042 if (fs_fd < 0)
3040 return; 3043 return;
3041 3044
3045 ev_ref (EV_A);
3042 ev_io_stop (EV_A_ &fs_w); 3046 ev_io_stop (EV_A_ &fs_w);
3043 close (fs_fd); 3047 close (fs_fd);
3044 fs_fd = infy_newfd (); 3048 fs_fd = infy_newfd ();
3045 3049
3046 if (fs_fd >= 0) 3050 if (fs_fd >= 0)
3047 { 3051 {
3048 fd_intern (fs_fd); 3052 fd_intern (fs_fd);
3049 ev_io_set (&fs_w, fs_fd, EV_READ); 3053 ev_io_set (&fs_w, fs_fd, EV_READ);
3050 ev_io_start (EV_A_ &fs_w); 3054 ev_io_start (EV_A_ &fs_w);
3055 ev_unref (EV_A);
3051 } 3056 }
3052 3057
3053 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3058 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot)
3054 { 3059 {
3055 WL w_ = fs_hash [slot].head; 3060 WL w_ = fs_hash [slot].head;
3063 w->wd = -1; 3068 w->wd = -1;
3064 3069
3065 if (fs_fd >= 0) 3070 if (fs_fd >= 0)
3066 infy_add (EV_A_ w); /* re-add, no matter what */ 3071 infy_add (EV_A_ w); /* re-add, no matter what */
3067 else 3072 else
3073 {
3074 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
3075 if (ev_is_active (&w->timer)) ev_ref (EV_A);
3068 ev_timer_again (EV_A_ &w->timer); 3076 ev_timer_again (EV_A_ &w->timer);
3077 if (ev_is_active (&w->timer)) ev_unref (EV_A);
3078 }
3069 } 3079 }
3070 } 3080 }
3071} 3081}
3072 3082
3073#endif 3083#endif
3143 3153
3144 if (fs_fd >= 0) 3154 if (fs_fd >= 0)
3145 infy_add (EV_A_ w); 3155 infy_add (EV_A_ w);
3146 else 3156 else
3147#endif 3157#endif
3158 {
3148 ev_timer_again (EV_A_ &w->timer); 3159 ev_timer_again (EV_A_ &w->timer);
3160 ev_unref (EV_A);
3161 }
3149 3162
3150 ev_start (EV_A_ (W)w, 1); 3163 ev_start (EV_A_ (W)w, 1);
3151 3164
3152 EV_FREQUENT_CHECK; 3165 EV_FREQUENT_CHECK;
3153} 3166}
3162 EV_FREQUENT_CHECK; 3175 EV_FREQUENT_CHECK;
3163 3176
3164#if EV_USE_INOTIFY 3177#if EV_USE_INOTIFY
3165 infy_del (EV_A_ w); 3178 infy_del (EV_A_ w);
3166#endif 3179#endif
3180
3181 if (ev_is_active (&w->timer))
3182 {
3183 ev_ref (EV_A);
3167 ev_timer_stop (EV_A_ &w->timer); 3184 ev_timer_stop (EV_A_ &w->timer);
3185 }
3168 3186
3169 ev_stop (EV_A_ (W)w); 3187 ev_stop (EV_A_ (W)w);
3170 3188
3171 EV_FREQUENT_CHECK; 3189 EV_FREQUENT_CHECK;
3172} 3190}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines