[前][次][番号順一覧][スレッド一覧]

ruby-changes:46502

From: nagachika <ko1@a...>
Date: Tue, 9 May 2017 23:24:25 +0900 (JST)
Subject: [ruby-changes:46502] nagachika:r58623 (ruby_2_4): merge revision(s) 58370, 58382: [Backport #13530]

nagachika	2017-05-09 23:24:20 +0900 (Tue, 09 May 2017)

  New Revision: 58623

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58623

  Log:
    merge revision(s) 58370,58382: [Backport #13530]
    
    thread_win32.c: no GVL for interrupt_event
    
    * thread_win32.c (w32_wait_events): do not acquire GVL, to fix
      deadlock at read/close race condition.  instead, just ignore
      interrupt_event if it is closed.
    thread_win32.c: fix index
    
    * thread_win32.c (w32_wait_events): fix wait object index in the
      case of interrupt_event is not usable.

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/thread_win32.c
    branches/ruby_2_4/version.h
Index: ruby_2_4/thread_win32.c
===================================================================
--- ruby_2_4/thread_win32.c	(revision 58622)
+++ ruby_2_4/thread_win32.c	(revision 58623)
@@ -158,53 +158,34 @@ Init_native_thread(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/thread_win32.c#L158
 		 th->native_thread_data.interrupt_event);
 }
 
-static void
-w32_set_event(HANDLE handle)
-{
-    if (SetEvent(handle) == 0) {
-	w32_error("w32_set_event");
-    }
-}
-
-static void
-w32_reset_event(HANDLE handle)
-{
-    if (ResetEvent(handle) == 0) {
-	w32_error("w32_reset_event");
-    }
-}
-
 static int
 w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
 {
     HANDLE *targets = events;
     HANDLE intr;
+    const int initcount = count;
     DWORD ret;
 
     thread_debug("  w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n",
 		 events, count, timeout, th);
     if (th && (intr = th->native_thread_data.interrupt_event)) {
-	gvl_acquire(th->vm, th);
-	if (intr == th->native_thread_data.interrupt_event) {
-	    w32_reset_event(intr);
-	    if (RUBY_VM_INTERRUPTED(th)) {
-		w32_set_event(intr);
-	    }
-
+	if (ResetEvent(intr) && (!RUBY_VM_INTERRUPTED(th) || SetEvent(intr))) {
 	    targets = ALLOCA_N(HANDLE, count + 1);
 	    memcpy(targets, events, sizeof(HANDLE) * count);
 
 	    targets[count++] = intr;
 	    thread_debug("  * handle: %p (count: %d, intr)\n", intr, count);
 	}
-	gvl_release(th->vm);
+	else if (intr == th->native_thread_data.interrupt_event) {
+	    w32_error("w32_wait_events");
+	}
     }
 
     thread_debug("  WaitForMultipleObjects start (count: %d)\n", count);
     ret = WaitForMultipleObjects(count, targets, FALSE, timeout);
     thread_debug("  WaitForMultipleObjects end (ret: %lu)\n", ret);
 
-    if (ret == (DWORD)(WAIT_OBJECT_0 + count - 1) && th) {
+    if (ret == (DWORD)(WAIT_OBJECT_0 + initcount) && th) {
 	errno = EINTR;
     }
     if (ret == WAIT_FAILED && THREAD_DEBUG) {
@@ -682,7 +663,9 @@ ubf_handle(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/thread_win32.c#L663
     rb_thread_t *th = (rb_thread_t *)ptr;
     thread_debug("ubf_handle: %p\n", th);
 
-    w32_set_event(th->native_thread_data.interrupt_event);
+    if (!SetEvent(th->native_thread_data.interrupt_event)) {
+	w32_error("ubf_handle");
+    }
 }
 
 static struct {
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 58622)
+++ ruby_2_4/version.h	(revision 58623)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.2"
 #define RUBY_RELEASE_DATE "2017-05-09"
-#define RUBY_PATCHLEVEL 117
+#define RUBY_PATCHLEVEL 118
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 5
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 58622)
+++ ruby_2_4	(revision 58623)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r58370,58382

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]