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.320 by root, Fri Dec 4 20:25:06 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
3089static void noinline 3101static void noinline
3090stat_timer_cb (EV_P_ ev_timer *w_, int revents) 3102stat_timer_cb (EV_P_ ev_timer *w_, int revents)
3091{ 3103{
3092 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 3104 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
3093 3105
3094 /* we copy this here each the time so that */ 3106 ev_statdata prev = w->attr;
3095 /* prev has the old value when the callback gets invoked */
3096 w->prev = w->attr;
3097 ev_stat_stat (EV_A_ w); 3107 ev_stat_stat (EV_A_ w);
3098 3108
3099 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */ 3109 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */
3100 if ( 3110 if (
3101 w->prev.st_dev != w->attr.st_dev 3111 prev.st_dev != w->attr.st_dev
3102 || w->prev.st_ino != w->attr.st_ino 3112 || prev.st_ino != w->attr.st_ino
3103 || w->prev.st_mode != w->attr.st_mode 3113 || prev.st_mode != w->attr.st_mode
3104 || w->prev.st_nlink != w->attr.st_nlink 3114 || prev.st_nlink != w->attr.st_nlink
3105 || w->prev.st_uid != w->attr.st_uid 3115 || prev.st_uid != w->attr.st_uid
3106 || w->prev.st_gid != w->attr.st_gid 3116 || prev.st_gid != w->attr.st_gid
3107 || w->prev.st_rdev != w->attr.st_rdev 3117 || prev.st_rdev != w->attr.st_rdev
3108 || w->prev.st_size != w->attr.st_size 3118 || prev.st_size != w->attr.st_size
3109 || w->prev.st_atime != w->attr.st_atime 3119 || prev.st_atime != w->attr.st_atime
3110 || w->prev.st_mtime != w->attr.st_mtime 3120 || prev.st_mtime != w->attr.st_mtime
3111 || w->prev.st_ctime != w->attr.st_ctime 3121 || prev.st_ctime != w->attr.st_ctime
3112 ) { 3122 ) {
3123 /* we only update w->prev on actual differences */
3124 /* in case we test more often than invoke the callback, */
3125 /* to ensure that prev is always different to attr */
3126 w->prev = prev;
3127
3113 #if EV_USE_INOTIFY 3128 #if EV_USE_INOTIFY
3114 if (fs_fd >= 0) 3129 if (fs_fd >= 0)
3115 { 3130 {
3116 infy_del (EV_A_ w); 3131 infy_del (EV_A_ w);
3117 infy_add (EV_A_ w); 3132 infy_add (EV_A_ w);
3142 3157
3143 if (fs_fd >= 0) 3158 if (fs_fd >= 0)
3144 infy_add (EV_A_ w); 3159 infy_add (EV_A_ w);
3145 else 3160 else
3146#endif 3161#endif
3162 {
3147 ev_timer_again (EV_A_ &w->timer); 3163 ev_timer_again (EV_A_ &w->timer);
3164 ev_unref (EV_A);
3165 }
3148 3166
3149 ev_start (EV_A_ (W)w, 1); 3167 ev_start (EV_A_ (W)w, 1);
3150 3168
3151 EV_FREQUENT_CHECK; 3169 EV_FREQUENT_CHECK;
3152} 3170}
3161 EV_FREQUENT_CHECK; 3179 EV_FREQUENT_CHECK;
3162 3180
3163#if EV_USE_INOTIFY 3181#if EV_USE_INOTIFY
3164 infy_del (EV_A_ w); 3182 infy_del (EV_A_ w);
3165#endif 3183#endif
3184
3185 if (ev_is_active (&w->timer))
3186 {
3187 ev_ref (EV_A);
3166 ev_timer_stop (EV_A_ &w->timer); 3188 ev_timer_stop (EV_A_ &w->timer);
3189 }
3167 3190
3168 ev_stop (EV_A_ (W)w); 3191 ev_stop (EV_A_ (W)w);
3169 3192
3170 EV_FREQUENT_CHECK; 3193 EV_FREQUENT_CHECK;
3171} 3194}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines