Project

General

Profile

Feature #4531 ยป 0001-rb_wait_for_single_fd-use-ppoll-instead-of-poll.patch

normalperson (Eric Wong), 05/05/2011 06:36 AM

View differences:

configure.in
1310 1310
	      dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
1311 1311
	      setsid telldir seekdir fchmod cosh sinh tanh log2 round\
1312 1312
	      setuid setgid daemon select_large_fdset setenv unsetenv\
1313
              mktime timegm gmtime_r clock_gettime gettimeofday poll\
1313
              mktime timegm gmtime_r clock_gettime gettimeofday ppoll\
1314 1314
              pread sendfile shutdown sigaltstack dl_iterate_phdr)
1315 1315

  
1316 1316
AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
include/ruby/io.h
28 28
#endif
29 29

  
30 30
#include "ruby/config.h"
31
#if defined(HAVE_POLL)
31
#if defined(HAVE_PPOLL)
32 32
#  include <poll.h>
33 33
#  define RB_WAITFD_IN  POLLIN
34 34
#  define RB_WAITFD_PRI POLLPRI
thread.c
2705 2705
}
2706 2706

  
2707 2707
/*
2708
 * poll() is supported by many OSes, but so far Linux is the only
2709
 * one we know of that supports using poll() in all places select()
2710
 * would work.
2708
 * while poll() is supported by many OSes, Linux is the only one we know of
2709
 * that supports using poll() in all places select() would work.  We now
2710
 * use ppoll() instead of poll() since it offers higher timeouts and
2711
 * higher resolution for compatibility with the select()-based implementation.
2711 2712
 */
2712
#if defined(HAVE_POLL) && defined(linux)
2713
#  define USE_POLL
2713
#if defined(HAVE_PPOLL) && defined(linux)
2714
#  define USE_PPOLL
2714 2715
#endif
2715 2716

  
2716
#ifdef USE_POLL
2717

  
2717
#ifdef USE_PPOLL
2718 2718

  
2719 2719
/* The same with linux kernel. TODO: make platform independent definition. */
2720 2720
#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
......
2729 2729
{
2730 2730
    struct pollfd fds;
2731 2731
    int result, lerrno;
2732
    double start;
2733
    int timeout = tv ? tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000 : -1;
2732
    double limit = 0;
2733
    struct timespec ts;
2734
    struct timespec *timeout = NULL;
2735

  
2736
    if (tv) {
2737
	ts.tv_sec = tv->tv_sec;
2738
	ts.tv_nsec = tv->tv_usec * 1000;
2739
	limit = timeofday();
2740
	limit += (double)tv->tv_sec + (double)tv->tv_usec * 1e-6;
2741
	timeout = &ts;
2742
    }
2734 2743

  
2735 2744
    fds.fd = fd;
2736 2745
    fds.events = (short)events;
2737 2746

  
2738 2747
retry:
2739 2748
    lerrno = 0;
2740
    start = timeofday();
2741 2749
    BLOCKING_REGION({
2742
	result = poll(&fds, 1, timeout);
2750
	result = ppoll(&fds, 1, timeout, NULL);
2743 2751
	if (result < 0) lerrno = errno;
2744 2752
    }, ubf_select, GET_THREAD());
2745 2753

  
......
2750 2758
#ifdef ERESTART
2751 2759
	  case ERESTART:
2752 2760
#endif
2753
	    if (timeout > 0) {
2754
		timeout -= (timeofday() - start) * 1000;
2755
		if (timeout < 0)
2756
		    timeout = 0;
2761
	    if (timeout) {
2762
		double d = limit - timeofday();
2763

  
2764
		ts.tv_sec = (long)d;
2765
		ts.tv_nsec = (long)((d - (double)ts.tv_sec) * 1e9);
2766
		if (ts.tv_sec < 0)
2767
		    ts.tv_sec = 0;
2768
		if (ts.tv_nsec < 0)
2769
		    ts.tv_nsec = 0;
2757 2770
	    }
2758 2771
	    goto retry;
2759 2772
	}
......
2779 2792

  
2780 2793
    return result;
2781 2794
}
2782
#else /* ! USE_POLL - implement rb_io_poll_fd() using select() */
2795
#else /* ! USE_PPOLL - implement rb_io_poll_fd() using select() */
2783 2796
static rb_fdset_t *init_set_fd(int fd, rb_fdset_t *fds)
2784 2797
{
2785 2798
    rb_fd_init(fds);
......
2853 2866

  
2854 2867
    return r;
2855 2868
}
2856
#endif /* ! USE_POLL */
2869
#endif /* ! USE_PPOLL */
2857 2870

  
2858 2871
/*
2859 2872
 * for GC
2860
-