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

Comparing libev/ev.c (file contents):
Revision 1.317 by root, Sat Nov 14 00:15:21 2009 UTC vs.
Revision 1.319 by root, Wed Nov 18 10:25:22 2009 UTC

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
2856static void noinline 2857static void noinline
2857infy_add (EV_P_ ev_stat *w) 2858infy_add (EV_P_ ev_stat *w)
2858{ 2859{
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); 2860 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);
2860 2861
2861 if (w->wd < 0) 2862 if (w->wd >= 0)
2863 {
2864 struct statfs sfs;
2865
2866 /* now local changes will be tracked by inotify, but remote changes won't */
2867 /* unless the filesystem is known to be local, we therefore still poll */
2868 /* also do poll on <2.6.25, but with normal frequency */
2869
2870 if (!fs_2625)
2871 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
2872 else if (!statfs (w->path, &sfs)
2873 && (sfs.f_type == 0x1373 /* devfs */
2874 || sfs.f_type == 0xEF53 /* ext2/3 */
2875 || sfs.f_type == 0x3153464a /* jfs */
2876 || sfs.f_type == 0x52654973 /* reiser3 */
2877 || sfs.f_type == 0x01021994 /* tempfs */
2878 || sfs.f_type == 0x58465342 /* xfs */))
2879 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */
2880 else
2881 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */
2862 { 2882 }
2883 else
2884 {
2885 /* can't use inotify, continue to stat */
2863 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; 2886 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
2864 ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2865 2887
2866 /* monitor some parent directory for speedup hints */ 2888 /* if path is not there, monitor some parent directory for speedup hints */
2867 /* note that exceeding the hardcoded path limit is not a correctness issue, */ 2889 /* note that exceeding the hardcoded path limit is not a correctness issue, */
2868 /* but an efficiency issue only */ 2890 /* but an efficiency issue only */
2869 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2891 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2870 { 2892 {
2871 char path [4096]; 2893 char path [4096];
2887 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 2909 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
2888 } 2910 }
2889 } 2911 }
2890 2912
2891 if (w->wd >= 0) 2913 if (w->wd >= 0)
2892 {
2893 struct statfs sfs;
2894
2895 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 2914 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w);
2896 2915
2897 /* now local changes will be tracked by inotify, but remote changes won't */ 2916 /* now re-arm timer, if required */
2898 /* unless the filesystem is known to be local, we therefore still poll */ 2917 if (ev_is_active (&w->timer)) ev_ref (EV_A);
2899 /* also do poll on <2.6.25, but with normal frequency */
2900
2901 if (fs_2625 && !statfs (w->path, &sfs))
2902 if (sfs.f_type == 0x1373 /* devfs */
2903 || sfs.f_type == 0xEF53 /* ext2/3 */
2904 || sfs.f_type == 0x3153464a /* jfs */
2905 || sfs.f_type == 0x52654973 /* reiser3 */
2906 || sfs.f_type == 0x01021994 /* tempfs */
2907 || sfs.f_type == 0x58465342 /* xfs */)
2908 return;
2909
2910 w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL;
2911 ev_timer_again (EV_A_ &w->timer); 2918 ev_timer_again (EV_A_ &w->timer);
2912 } 2919 if (ev_is_active (&w->timer)) ev_unref (EV_A);
2913} 2920}
2914 2921
2915static void noinline 2922static void noinline
2916infy_del (EV_P_ ev_stat *w) 2923infy_del (EV_P_ ev_stat *w)
2917{ 2924{
3062 w->wd = -1; 3069 w->wd = -1;
3063 3070
3064 if (fs_fd >= 0) 3071 if (fs_fd >= 0)
3065 infy_add (EV_A_ w); /* re-add, no matter what */ 3072 infy_add (EV_A_ w); /* re-add, no matter what */
3066 else 3073 else
3074 {
3075 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
3076 if (ev_is_active (&w->timer)) ev_ref (EV_A);
3067 ev_timer_again (EV_A_ &w->timer); 3077 ev_timer_again (EV_A_ &w->timer);
3078 if (ev_is_active (&w->timer)) ev_unref (EV_A);
3079 }
3068 } 3080 }
3069 } 3081 }
3070} 3082}
3071 3083
3072#endif 3084#endif
3142 3154
3143 if (fs_fd >= 0) 3155 if (fs_fd >= 0)
3144 infy_add (EV_A_ w); 3156 infy_add (EV_A_ w);
3145 else 3157 else
3146#endif 3158#endif
3159 {
3147 ev_timer_again (EV_A_ &w->timer); 3160 ev_timer_again (EV_A_ &w->timer);
3161 ev_unref (EV_A);
3162 }
3148 3163
3149 ev_start (EV_A_ (W)w, 1); 3164 ev_start (EV_A_ (W)w, 1);
3150 3165
3151 EV_FREQUENT_CHECK; 3166 EV_FREQUENT_CHECK;
3152} 3167}
3161 EV_FREQUENT_CHECK; 3176 EV_FREQUENT_CHECK;
3162 3177
3163#if EV_USE_INOTIFY 3178#if EV_USE_INOTIFY
3164 infy_del (EV_A_ w); 3179 infy_del (EV_A_ w);
3165#endif 3180#endif
3181
3182 if (ev_is_active (&w->timer))
3183 {
3184 ev_ref (EV_A);
3166 ev_timer_stop (EV_A_ &w->timer); 3185 ev_timer_stop (EV_A_ &w->timer);
3186 }
3167 3187
3168 ev_stop (EV_A_ (W)w); 3188 ev_stop (EV_A_ (W)w);
3169 3189
3170 EV_FREQUENT_CHECK; 3190 EV_FREQUENT_CHECK;
3171} 3191}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines