… | |
… | |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
30 | */ |
31 | #ifndef EV_EMBED |
31 | #ifndef EV_STANDALONE |
32 | # include "config.h" |
32 | # include "config.h" |
|
|
33 | |
|
|
34 | # if HAVE_CLOCK_GETTIME |
|
|
35 | # define EV_USE_MONOTONIC 1 |
|
|
36 | # define EV_USE_REALTIME 1 |
|
|
37 | # endif |
|
|
38 | |
|
|
39 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
40 | # define EV_USE_SELECT 1 |
|
|
41 | # endif |
|
|
42 | |
|
|
43 | # if HAVE_POLL && HAVE_POLL_H |
|
|
44 | # define EV_USE_POLL 1 |
|
|
45 | # endif |
|
|
46 | |
|
|
47 | # if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
|
|
48 | # define EV_USE_EPOLL 1 |
|
|
49 | # endif |
|
|
50 | |
|
|
51 | # if HAVE_KQUEUE && HAVE_WORKING_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H |
|
|
52 | # define EV_USE_KQUEUE 1 |
|
|
53 | # endif |
|
|
54 | |
33 | #endif |
55 | #endif |
34 | |
56 | |
35 | #include <math.h> |
57 | #include <math.h> |
36 | #include <stdlib.h> |
58 | #include <stdlib.h> |
37 | #include <unistd.h> |
59 | #include <unistd.h> |
… | |
… | |
58 | |
80 | |
59 | #ifndef EV_USE_SELECT |
81 | #ifndef EV_USE_SELECT |
60 | # define EV_USE_SELECT 1 |
82 | # define EV_USE_SELECT 1 |
61 | #endif |
83 | #endif |
62 | |
84 | |
63 | #ifndef EV_USEV_POLL |
85 | #ifndef EV_USE_POLL |
64 | # define EV_USEV_POLL 0 /* poll is usually slower than select, and not as well tested */ |
86 | # define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ |
65 | #endif |
87 | #endif |
66 | |
88 | |
67 | #ifndef EV_USE_EPOLL |
89 | #ifndef EV_USE_EPOLL |
68 | # define EV_USE_EPOLL 0 |
90 | # define EV_USE_EPOLL 0 |
69 | #endif |
91 | #endif |
… | |
… | |
93 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
115 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
94 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
116 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
95 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
117 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
96 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
118 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
97 | |
119 | |
98 | #ifndef EV_EMBED |
|
|
99 | # include "ev.h" |
120 | #include "ev.h" |
100 | #endif |
|
|
101 | |
121 | |
102 | #if __GNUC__ >= 3 |
122 | #if __GNUC__ >= 3 |
103 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
123 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
104 | # define inline inline |
124 | # define inline inline |
105 | #else |
125 | #else |
… | |
… | |
351 | /* this should be highly optimised to not do anything but set a flag */ |
371 | /* this should be highly optimised to not do anything but set a flag */ |
352 | for (fd = 0; fd < anfdmax; ++fd) |
372 | for (fd = 0; fd < anfdmax; ++fd) |
353 | if (anfds [fd].events) |
373 | if (anfds [fd].events) |
354 | { |
374 | { |
355 | anfds [fd].events = 0; |
375 | anfds [fd].events = 0; |
356 | fd_change (fd); |
376 | fd_change (EV_A_ fd); |
357 | } |
377 | } |
358 | } |
378 | } |
359 | |
379 | |
360 | /*****************************************************************************/ |
380 | /*****************************************************************************/ |
361 | |
381 | |
… | |
… | |
411 | static ANSIG *signals; |
431 | static ANSIG *signals; |
412 | static int signalmax; |
432 | static int signalmax; |
413 | |
433 | |
414 | static int sigpipe [2]; |
434 | static int sigpipe [2]; |
415 | static sig_atomic_t volatile gotsig; |
435 | static sig_atomic_t volatile gotsig; |
|
|
436 | static struct ev_io sigev; |
416 | |
437 | |
417 | static void |
438 | static void |
418 | signals_init (ANSIG *base, int count) |
439 | signals_init (ANSIG *base, int count) |
419 | { |
440 | { |
420 | while (count--) |
441 | while (count--) |
… | |
… | |
477 | } |
498 | } |
478 | |
499 | |
479 | /*****************************************************************************/ |
500 | /*****************************************************************************/ |
480 | |
501 | |
481 | #ifndef WIN32 |
502 | #ifndef WIN32 |
|
|
503 | |
|
|
504 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
505 | static struct ev_signal childev; |
482 | |
506 | |
483 | #ifndef WCONTINUED |
507 | #ifndef WCONTINUED |
484 | # define WCONTINUED 0 |
508 | # define WCONTINUED 0 |
485 | #endif |
509 | #endif |
486 | |
510 | |
… | |
… | |
522 | # include "ev_kqueue.c" |
546 | # include "ev_kqueue.c" |
523 | #endif |
547 | #endif |
524 | #if EV_USE_EPOLL |
548 | #if EV_USE_EPOLL |
525 | # include "ev_epoll.c" |
549 | # include "ev_epoll.c" |
526 | #endif |
550 | #endif |
527 | #if EV_USEV_POLL |
551 | #if EV_USE_POLL |
528 | # include "ev_poll.c" |
552 | # include "ev_poll.c" |
529 | #endif |
553 | #endif |
530 | #if EV_USE_SELECT |
554 | #if EV_USE_SELECT |
531 | # include "ev_select.c" |
555 | # include "ev_select.c" |
532 | #endif |
556 | #endif |
… | |
… | |
590 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
614 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
591 | #endif |
615 | #endif |
592 | #if EV_USE_EPOLL |
616 | #if EV_USE_EPOLL |
593 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
617 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
594 | #endif |
618 | #endif |
595 | #if EV_USEV_POLL |
619 | #if EV_USE_POLL |
596 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
620 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
597 | #endif |
621 | #endif |
598 | #if EV_USE_SELECT |
622 | #if EV_USE_SELECT |
599 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
623 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
600 | #endif |
624 | #endif |
… | |
… | |
608 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
632 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
609 | #endif |
633 | #endif |
610 | #if EV_USE_EPOLL |
634 | #if EV_USE_EPOLL |
611 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
635 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
612 | #endif |
636 | #endif |
613 | #if EV_USEV_POLL |
637 | #if EV_USE_POLL |
614 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
638 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
615 | #endif |
639 | #endif |
616 | #if EV_USE_SELECT |
640 | #if EV_USE_SELECT |
617 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
641 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
618 | #endif |
642 | #endif |
… | |
… | |
639 | { |
663 | { |
640 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
664 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
641 | |
665 | |
642 | loop_init (EV_A_ methods); |
666 | loop_init (EV_A_ methods); |
643 | |
667 | |
644 | if (ev_methods (EV_A)) |
668 | if (ev_method (EV_A)) |
645 | return loop; |
669 | return loop; |
646 | |
670 | |
647 | return 0; |
671 | return 0; |
648 | } |
672 | } |
649 | |
673 | |
… | |
… | |
726 | |
750 | |
727 | loop_destroy (EV_A); |
751 | loop_destroy (EV_A); |
728 | } |
752 | } |
729 | |
753 | |
730 | void |
754 | void |
731 | ev_default_fork (EV_P) |
755 | ev_default_fork (void) |
732 | { |
756 | { |
|
|
757 | #if EV_MULTIPLICITY |
|
|
758 | struct ev_loop *loop = default_loop; |
|
|
759 | #endif |
|
|
760 | |
733 | loop_fork (EV_A); |
761 | loop_fork (EV_A); |
734 | |
762 | |
735 | ev_io_stop (EV_A_ &sigev); |
763 | ev_io_stop (EV_A_ &sigev); |
736 | close (sigpipe [0]); |
764 | close (sigpipe [0]); |
737 | close (sigpipe [1]); |
765 | close (sigpipe [1]); |