ruby-changes:20060
From: usa <ko1@a...>
Date: Thu, 16 Jun 2011 03:05:16 +0900 (JST)
Subject: [ruby-changes:20060] usa:r32107 (trunk): * thread.c (do_select): Windows: no need to poll if select(2) is
usa 2011-06-16 03:04:13 +0900 (Thu, 16 Jun 2011) New Revision: 32107 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32107 Log: * thread.c (do_select): Windows: no need to poll if select(2) is cancelable. * thread_win32.c (native_fd_select): new function to make select(2) cancelable. * thread_win32.c (rb_w32_check_interrupt): new function for checking interrupt. * win32/win32.c (rb_w32_select_with_thread): new function. cancelable select(2). * win32/win32.c (rb_w32_select): use above function internally. Modified files: trunk/ChangeLog trunk/thread.c trunk/thread_win32.c trunk/win32/win32.c Index: thread_win32.c =================================================================== --- thread_win32.c (revision 32106) +++ thread_win32.c (revision 32107) @@ -673,6 +673,34 @@ #endif /* USE_NATIVE_THREAD_PRIORITY */ +int rb_w32_select_with_thread(int, fd_set *, fd_set *, fd_set *, struct timeval *, void *); /* @internal */ + +static int +native_fd_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *exceptfds, struct timeval *timeout, rb_thread_t *th) +{ + fd_set *r = NULL, *w = NULL, *e = NULL; + if (readfds) { + rb_fd_resize(n - 1, readfds); + r = rb_fd_ptr(readfds); + } + if (writefds) { + rb_fd_resize(n - 1, writefds); + w = rb_fd_ptr(writefds); + } + if (exceptfds) { + rb_fd_resize(n - 1, exceptfds); + e = rb_fd_ptr(exceptfds); + } + return rb_w32_select_with_thread(n, r, w, e, timeout, th); +} + +/* @internal */ +int +rb_w32_check_interrupt(rb_thread_t *th) +{ + return w32_wait_events(0, 0, 0, th); +} + static void ubf_handle(void *ptr) { Index: ChangeLog =================================================================== --- ChangeLog (revision 32106) +++ ChangeLog (revision 32107) @@ -1,3 +1,19 @@ +Thu Jun 16 03:00:26 2011 NAKAMURA Usaku <usa@r...> + + * thread.c (do_select): Windows: no need to poll if select(2) is + cancelable. + + * thread_win32.c (native_fd_select): new function to make select(2) + cancelable. + + * thread_win32.c (rb_w32_check_interrupt): new function for checking + interrupt. + + * win32/win32.c (rb_w32_select_with_thread): new function. cancelable + select(2). + + * win32/win32.c (rb_w32_select): use above function internally. + Wed Jun 15 23:30:45 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * gc.c: fix a regression by r31690 on AIX because AIX malloc Index: thread.c =================================================================== --- thread.c (revision 32106) +++ thread.c (revision 32107) @@ -2537,7 +2537,7 @@ # endif if (timeout) { -# if defined(__CYGWIN__) || defined(_WIN32) +# if defined(__CYGWIN__) gettimeofday(&start_time, NULL); limit = (double)start_time.tv_sec + (double)start_time.tv_usec*1e-6; # else @@ -2558,7 +2558,7 @@ retry: lerrno = 0; -#if defined(__CYGWIN__) || defined(_WIN32) +#if defined(__CYGWIN__) { int finish = 0; /* polling duration: 100ms */ @@ -2595,6 +2595,14 @@ }, 0, 0); } while (result == 0 && !finish); } +#elif defined(_WIN32) + { + rb_thread_t *th = GET_THREAD(); + BLOCKING_REGION({ + result = native_fd_select(n, read, write, except, timeout, th); + if (result < 0) lerrno = errno; + }, ubf_select, th); + } #else BLOCKING_REGION({ result = rb_fd_select(n, read, write, except, timeout); Index: win32/win32.c =================================================================== --- win32/win32.c (revision 32106) +++ win32/win32.c (revision 32107) @@ -2591,9 +2591,13 @@ } #undef Sleep -int WSAAPI -rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, - struct timeval *timeout) + +int rb_w32_check_interrupt(void *); /* @internal */ + +/* @internal */ +int +rb_w32_select_with_thread(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, + struct timeval *timeout, void *th) { int r; rb_fdset_t pipe_rd; @@ -2672,6 +2676,10 @@ wait.tv_sec = 0; wait.tv_usec = 10 * 1000; // 10ms zero.tv_sec = 0; zero.tv_usec = 0; // 0ms for (;;) { + if (th && rb_w32_check_interrupt(th) != WAIT_TIMEOUT) { + r = -1; + break; + } if (nonsock) { // modifying {else,pipe,cons}_rd is safe because // if they are modified, function returns immediately. @@ -2724,6 +2732,13 @@ return r; } +int WSAAPI +rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, + struct timeval *timeout) +{ + return rb_w32_select_with_thread(nfds, rd, wr, ex, timeout, 0); +} + static FARPROC get_wsa_extension_function(SOCKET s, GUID *guid) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/