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

Comparing libev/ev.c (file contents):
Revision 1.57 by root, Sun Nov 4 16:43:53 2007 UTC vs.
Revision 1.61 by root, Sun Nov 4 19:45:09 2007 UTC

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_STANDALONE 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
349 /* 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 */
350 for (fd = 0; fd < anfdmax; ++fd) 372 for (fd = 0; fd < anfdmax; ++fd)
351 if (anfds [fd].events) 373 if (anfds [fd].events)
352 { 374 {
353 anfds [fd].events = 0; 375 anfds [fd].events = 0;
354 fd_change (fd); 376 fd_change (EV_A_ fd);
355 } 377 }
356} 378}
357 379
358/*****************************************************************************/ 380/*****************************************************************************/
359 381
409static ANSIG *signals; 431static ANSIG *signals;
410static int signalmax; 432static int signalmax;
411 433
412static int sigpipe [2]; 434static int sigpipe [2];
413static sig_atomic_t volatile gotsig; 435static sig_atomic_t volatile gotsig;
436static struct ev_io sigev;
414 437
415static void 438static void
416signals_init (ANSIG *base, int count) 439signals_init (ANSIG *base, int count)
417{ 440{
418 while (count--) 441 while (count--)
475} 498}
476 499
477/*****************************************************************************/ 500/*****************************************************************************/
478 501
479#ifndef WIN32 502#ifndef WIN32
503
504static struct ev_child *childs [PID_HASHSIZE];
505static struct ev_signal childev;
480 506
481#ifndef WCONTINUED 507#ifndef WCONTINUED
482# define WCONTINUED 0 508# define WCONTINUED 0
483#endif 509#endif
484 510
520# include "ev_kqueue.c" 546# include "ev_kqueue.c"
521#endif 547#endif
522#if EV_USE_EPOLL 548#if EV_USE_EPOLL
523# include "ev_epoll.c" 549# include "ev_epoll.c"
524#endif 550#endif
525#if EV_USEV_POLL 551#if EV_USE_POLL
526# include "ev_poll.c" 552# include "ev_poll.c"
527#endif 553#endif
528#if EV_USE_SELECT 554#if EV_USE_SELECT
529# include "ev_select.c" 555# include "ev_select.c"
530#endif 556#endif
588 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 614 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
589#endif 615#endif
590#if EV_USE_EPOLL 616#if EV_USE_EPOLL
591 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 617 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
592#endif 618#endif
593#if EV_USEV_POLL 619#if EV_USE_POLL
594 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 620 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
595#endif 621#endif
596#if EV_USE_SELECT 622#if EV_USE_SELECT
597 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 623 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
598#endif 624#endif
606 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 632 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
607#endif 633#endif
608#if EV_USE_EPOLL 634#if EV_USE_EPOLL
609 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 635 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
610#endif 636#endif
611#if EV_USEV_POLL 637#if EV_USE_POLL
612 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 638 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
613#endif 639#endif
614#if EV_USE_SELECT 640#if EV_USE_SELECT
615 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 641 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
616#endif 642#endif
637{ 663{
638 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));
639 665
640 loop_init (EV_A_ methods); 666 loop_init (EV_A_ methods);
641 667
642 if (ev_methods (EV_A)) 668 if (ev_method (EV_A))
643 return loop; 669 return loop;
644 670
645 return 0; 671 return 0;
646} 672}
647 673
724 750
725 loop_destroy (EV_A); 751 loop_destroy (EV_A);
726} 752}
727 753
728void 754void
729ev_default_fork (EV_P) 755ev_default_fork (void)
730{ 756{
757#if EV_MULTIPLICITY
758 struct ev_loop *loop = default_loop;
759#endif
760
731 loop_fork (EV_A); 761 loop_fork (EV_A);
732 762
733 ev_io_stop (EV_A_ &sigev); 763 ev_io_stop (EV_A_ &sigev);
734 close (sigpipe [0]); 764 close (sigpipe [0]);
735 close (sigpipe [1]); 765 close (sigpipe [1]);
763timers_reify (EV_P) 793timers_reify (EV_P)
764{ 794{
765 while (timercnt && timers [0]->at <= mn_now) 795 while (timercnt && timers [0]->at <= mn_now)
766 { 796 {
767 struct ev_timer *w = timers [0]; 797 struct ev_timer *w = timers [0];
798
799 assert (("inactive timer on timer heap detected", ev_is_active (w)));
768 800
769 /* first reschedule or stop timer */ 801 /* first reschedule or stop timer */
770 if (w->repeat) 802 if (w->repeat)
771 { 803 {
772 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 804 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
785{ 817{
786 while (periodiccnt && periodics [0]->at <= rt_now) 818 while (periodiccnt && periodics [0]->at <= rt_now)
787 { 819 {
788 struct ev_periodic *w = periodics [0]; 820 struct ev_periodic *w = periodics [0];
789 821
822 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
823
790 /* first reschedule or stop timer */ 824 /* first reschedule or stop timer */
791 if (w->interval) 825 if (w->interval)
792 { 826 {
793 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; 827 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval;
794 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); 828 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines