… | |
… | |
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); |
… | |
… | |
2897 | struct statfs sfs; |
2893 | struct statfs sfs; |
2898 | |
2894 | |
2899 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2895 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2900 | |
2896 | |
2901 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2897 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2902 | /* unless the filesystem it known to be local, we therefore still poll */ |
2898 | /* unless the filesystem is known to be local, we therefore still poll */ |
2903 | /* also do poll on <2.6.25, but with normal frequency */ |
2899 | /* also do poll on <2.6.25, but with normal frequency */ |
2904 | |
2900 | |
2905 | if (fs_2625 && !statfs (w->path, &sfs)) |
2901 | if (fs_2625 && !statfs (w->path, &sfs)) |
2906 | if (sfs.f_type == 0x1373 /* devfs */ |
2902 | if (sfs.f_type == 0x1373 /* devfs */ |
2907 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
2903 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
… | |
… | |
2997 | return; |
2993 | return; |
2998 | |
2994 | |
2999 | fs_2625 = 1; |
2995 | fs_2625 = 1; |
3000 | } |
2996 | } |
3001 | |
2997 | |
|
|
2998 | inline_size int |
|
|
2999 | infy_newfd (void) |
|
|
3000 | { |
|
|
3001 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
|
|
3002 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
|
|
3003 | if (fd >= 0) |
|
|
3004 | return fd; |
|
|
3005 | #endif |
|
|
3006 | return inotify_init (); |
|
|
3007 | } |
|
|
3008 | |
3002 | inline_size void |
3009 | inline_size void |
3003 | infy_init (EV_P) |
3010 | infy_init (EV_P) |
3004 | { |
3011 | { |
3005 | if (fs_fd != -2) |
3012 | if (fs_fd != -2) |
3006 | return; |
3013 | return; |
3007 | |
3014 | |
3008 | fs_fd = -1; |
3015 | fs_fd = -1; |
3009 | |
3016 | |
3010 | check_2625 (EV_A); |
3017 | check_2625 (EV_A); |
3011 | |
3018 | |
3012 | fs_fd = inotify_init (); |
3019 | fs_fd = infy_newfd (); |
3013 | |
3020 | |
3014 | if (fs_fd >= 0) |
3021 | if (fs_fd >= 0) |
3015 | { |
3022 | { |
|
|
3023 | fd_intern (fs_fd); |
3016 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3024 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3017 | ev_set_priority (&fs_w, EV_MAXPRI); |
3025 | ev_set_priority (&fs_w, EV_MAXPRI); |
3018 | ev_io_start (EV_A_ &fs_w); |
3026 | ev_io_start (EV_A_ &fs_w); |
|
|
3027 | ev_unref (EV_A); |
3019 | } |
3028 | } |
3020 | } |
3029 | } |
3021 | |
3030 | |
3022 | inline_size void |
3031 | inline_size void |
3023 | infy_fork (EV_P) |
3032 | infy_fork (EV_P) |
… | |
… | |
3025 | int slot; |
3034 | int slot; |
3026 | |
3035 | |
3027 | if (fs_fd < 0) |
3036 | if (fs_fd < 0) |
3028 | return; |
3037 | return; |
3029 | |
3038 | |
|
|
3039 | ev_ref (EV_A); |
|
|
3040 | ev_io_stop (EV_A_ &fs_w); |
3030 | close (fs_fd); |
3041 | close (fs_fd); |
3031 | fs_fd = inotify_init (); |
3042 | fs_fd = infy_newfd (); |
|
|
3043 | |
|
|
3044 | if (fs_fd >= 0) |
|
|
3045 | { |
|
|
3046 | fd_intern (fs_fd); |
|
|
3047 | ev_io_set (&fs_w, fs_fd, EV_READ); |
|
|
3048 | ev_io_start (EV_A_ &fs_w); |
|
|
3049 | ev_unref (EV_A); |
|
|
3050 | } |
3032 | |
3051 | |
3033 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3052 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3034 | { |
3053 | { |
3035 | WL w_ = fs_hash [slot].head; |
3054 | WL w_ = fs_hash [slot].head; |
3036 | fs_hash [slot].head = 0; |
3055 | fs_hash [slot].head = 0; |