… | |
… | |
386 | # include <stdint.h> |
386 | # include <stdint.h> |
387 | # ifndef EFD_NONBLOCK |
387 | # ifndef EFD_NONBLOCK |
388 | # define EFD_NONBLOCK O_NONBLOCK |
388 | # define EFD_NONBLOCK O_NONBLOCK |
389 | # endif |
389 | # endif |
390 | # ifndef EFD_CLOEXEC |
390 | # ifndef EFD_CLOEXEC |
|
|
391 | # ifdef O_CLOEXEC |
391 | # define EFD_CLOEXEC O_CLOEXEC |
392 | # define EFD_CLOEXEC O_CLOEXEC |
|
|
393 | # else |
|
|
394 | # define EFD_CLOEXEC 02000000 |
|
|
395 | # endif |
392 | # endif |
396 | # endif |
393 | # ifdef __cplusplus |
397 | # ifdef __cplusplus |
394 | extern "C" { |
398 | extern "C" { |
395 | # endif |
399 | # endif |
396 | int eventfd (unsigned int initval, int flags); |
400 | int eventfd (unsigned int initval, int flags); |
… | |
… | |
472 | |
476 | |
473 | #if EV_USE_MONOTONIC |
477 | #if EV_USE_MONOTONIC |
474 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
478 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
475 | #endif |
479 | #endif |
476 | |
480 | |
|
|
481 | #ifndef EV_FD_TO_WIN32_HANDLE |
|
|
482 | # define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) |
|
|
483 | #endif |
|
|
484 | #ifndef EV_WIN32_HANDLE_TO_FD |
|
|
485 | # define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (fd, 0) |
|
|
486 | #endif |
|
|
487 | #ifndef EV_WIN32_CLOSE_FD |
|
|
488 | # define EV_WIN32_CLOSE_FD(fd) close (fd) |
|
|
489 | #endif |
|
|
490 | |
477 | #ifdef _WIN32 |
491 | #ifdef _WIN32 |
478 | # include "ev_win32.c" |
492 | # include "ev_win32.c" |
479 | #endif |
493 | #endif |
480 | |
494 | |
481 | /*****************************************************************************/ |
495 | /*****************************************************************************/ |
… | |
… | |
872 | |
886 | |
873 | #if EV_SELECT_IS_WINSOCKET |
887 | #if EV_SELECT_IS_WINSOCKET |
874 | if (events) |
888 | if (events) |
875 | { |
889 | { |
876 | unsigned long arg; |
890 | unsigned long arg; |
877 | #ifdef EV_FD_TO_WIN32_HANDLE |
|
|
878 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
891 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
879 | #else |
|
|
880 | anfd->handle = _get_osfhandle (fd); |
|
|
881 | #endif |
|
|
882 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
892 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
883 | } |
893 | } |
884 | #endif |
894 | #endif |
885 | |
895 | |
886 | { |
896 | { |
… | |
… | |
1057 | |
1067 | |
1058 | for (;;) |
1068 | for (;;) |
1059 | { |
1069 | { |
1060 | int c = k << 1; |
1070 | int c = k << 1; |
1061 | |
1071 | |
1062 | if (c > N + HEAP0 - 1) |
1072 | if (c >= N + HEAP0) |
1063 | break; |
1073 | break; |
1064 | |
1074 | |
1065 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1075 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1066 | ? 1 : 0; |
1076 | ? 1 : 0; |
1067 | |
1077 | |
… | |
… | |
1103 | |
1113 | |
1104 | /* move an element suitably so it is in a correct place */ |
1114 | /* move an element suitably so it is in a correct place */ |
1105 | inline_size void |
1115 | inline_size void |
1106 | adjustheap (ANHE *heap, int N, int k) |
1116 | adjustheap (ANHE *heap, int N, int k) |
1107 | { |
1117 | { |
1108 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
1118 | if (k > HEAP0 && ANHE_at (heap [k]) <= ANHE_at (heap [HPARENT (k)])) |
1109 | upheap (heap, k); |
1119 | upheap (heap, k); |
1110 | else |
1120 | else |
1111 | downheap (heap, N, k); |
1121 | downheap (heap, N, k); |
1112 | } |
1122 | } |
1113 | |
1123 | |
… | |
… | |
1617 | close (evfd); |
1627 | close (evfd); |
1618 | #endif |
1628 | #endif |
1619 | |
1629 | |
1620 | if (evpipe [0] >= 0) |
1630 | if (evpipe [0] >= 0) |
1621 | { |
1631 | { |
1622 | close (evpipe [0]); |
1632 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1623 | close (evpipe [1]); |
1633 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1624 | } |
1634 | } |
1625 | } |
1635 | } |
1626 | |
1636 | |
1627 | #if EV_USE_SIGNALFD |
1637 | #if EV_USE_SIGNALFD |
1628 | if (ev_is_active (&sigfd_w)) |
1638 | if (ev_is_active (&sigfd_w)) |
… | |
… | |
1724 | close (evfd); |
1734 | close (evfd); |
1725 | #endif |
1735 | #endif |
1726 | |
1736 | |
1727 | if (evpipe [0] >= 0) |
1737 | if (evpipe [0] >= 0) |
1728 | { |
1738 | { |
1729 | close (evpipe [0]); |
1739 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1730 | close (evpipe [1]); |
1740 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1731 | } |
1741 | } |
1732 | |
1742 | |
1733 | evpipe_init (EV_A); |
1743 | evpipe_init (EV_A); |
1734 | /* now iterate over everything, in case we missed something */ |
1744 | /* now iterate over everything, in case we missed something */ |
1735 | pipecb (EV_A_ &pipe_w, EV_READ); |
1745 | pipecb (EV_A_ &pipe_w, EV_READ); |
… | |
… | |
2671 | return; |
2681 | return; |
2672 | |
2682 | |
2673 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
2683 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
2674 | |
2684 | |
2675 | #if EV_MULTIPLICITY |
2685 | #if EV_MULTIPLICITY |
2676 | assert (("libev: tried to attach to a signal from two different loops", |
2686 | assert (("libev: a signal must not be attached to two different loops", |
2677 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
2687 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
2678 | |
2688 | |
2679 | signals [w->signum - 1].loop = EV_A; |
2689 | signals [w->signum - 1].loop = EV_A; |
2680 | #endif |
2690 | #endif |
2681 | |
2691 | |
… | |
… | |
2857 | } |
2867 | } |
2858 | } |
2868 | } |
2859 | |
2869 | |
2860 | if (w->wd >= 0) |
2870 | if (w->wd >= 0) |
2861 | { |
2871 | { |
|
|
2872 | struct statfs sfs; |
|
|
2873 | |
2862 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2874 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2863 | |
2875 | |
2864 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2876 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2865 | /* unless the filesystem it known to be local, we therefore still poll */ |
2877 | /* unless the filesystem it known to be local, we therefore still poll */ |
2866 | /* also do poll on <2.6.25, but with normal frequency */ |
2878 | /* also do poll on <2.6.25, but with normal frequency */ |
2867 | struct statfs sfs; |
|
|
2868 | |
2879 | |
2869 | if (fs_2625 && !statfs (w->path, &sfs)) |
2880 | if (fs_2625 && !statfs (w->path, &sfs)) |
2870 | if (sfs.f_type == 0x1373 /* devfs */ |
2881 | if (sfs.f_type == 0x1373 /* devfs */ |
2871 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
2882 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
2872 | || sfs.f_type == 0x3153464a /* jfs */ |
2883 | || sfs.f_type == 0x3153464a /* jfs */ |