From a8bdd28d10c2c5981e944e945eed95f6c4ad44bc Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 15 Jun 2011 18:04:13 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_win32.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'thread_win32.c') diff --git a/thread_win32.c b/thread_win32.c index 668d94b6c7..172c942033 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -673,6 +673,34 @@ native_thread_apply_priority(rb_thread_t *th) #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) { -- cgit v1.2.3