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

ruby-changes:54723

From: naruse <ko1@a...>
Date: Tue, 29 Jan 2019 14:31:05 +0900 (JST)
Subject: [ruby-changes:54723] naruse:r66940 (ruby_2_6): merge revision(s) 66708: [Backport #15499]

naruse	2019-01-29 14:31:00 +0900 (Tue, 29 Jan 2019)

  New Revision: 66940

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

  Log:
    merge revision(s) 66708: [Backport #15499]
    
    thread.c (call_without_gvl): spawn thread for UBF iff single-threaded
    
    We need another native thread to call some unblocking functions
    which aren't RUBY_UBF_IO or RUBY_UBF_PROCESS.  Instead of a
    permanent thread in <= 2.5, we can now rely on the thread cache
    feature to perform interrupts.
    
    [ruby-core:90865] [Bug #15499]

  Modified directories:
    branches/ruby_2_6/
  Modified files:
    branches/ruby_2_6/thread.c
    branches/ruby_2_6/thread_pthread.c
    branches/ruby_2_6/thread_win32.c
    branches/ruby_2_6/version.h
Index: ruby_2_6/version.h
===================================================================
--- ruby_2_6/version.h	(revision 66939)
+++ ruby_2_6/version.h	(revision 66940)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/version.h#L1
 #define RUBY_VERSION "2.6.1"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 30
+#define RUBY_PATCHLEVEL 31
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 1
Index: ruby_2_6/thread_pthread.c
===================================================================
--- ruby_2_6/thread_pthread.c	(revision 66939)
+++ ruby_2_6/thread_pthread.c	(revision 66940)
@@ -2206,4 +2206,23 @@ timer_pthread_fn(void *p) https://github.com/ruby/ruby/blob/trunk/ruby_2_6/thread_pthread.c#L2206
     return 0;
 }
 #endif /* UBF_TIMER_PTHREAD */
+
+static VALUE
+ubf_caller(const void *ignore)
+{
+    rb_thread_sleep_forever();
+
+    return Qfalse;
+}
+
+/*
+ * Called if and only if one thread is running, and
+ * the unblock function is NOT async-signal-safe
+ * This assumes USE_THREAD_CACHE is true for performance reasons
+ */
+static VALUE
+rb_thread_start_unblock_thread(void)
+{
+    return rb_thread_create(ubf_caller, 0);
+}
 #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
Index: ruby_2_6/thread.c
===================================================================
--- ruby_2_6/thread.c	(revision 66939)
+++ ruby_2_6/thread.c	(revision 66940)
@@ -1429,11 +1429,15 @@ call_without_gvl(void *(*func)(void *), https://github.com/ruby/ruby/blob/trunk/ruby_2_6/thread.c#L1429
     rb_execution_context_t *ec = GET_EC();
     rb_thread_t *th = rb_ec_thread_ptr(ec);
     int saved_errno = 0;
+    VALUE ubf_th = Qfalse;
 
     if (ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
 	ubf = ubf_select;
 	data2 = th;
     }
+    else if (ubf && vm_living_thread_num(th->vm) == 1) {
+	ubf_th = rb_thread_start_unblock_thread();
+    }
 
     BLOCKING_REGION(th, {
 	val = func(data1);
@@ -1444,6 +1448,10 @@ call_without_gvl(void *(*func)(void *), https://github.com/ruby/ruby/blob/trunk/ruby_2_6/thread.c#L1448
 	RUBY_VM_CHECK_INTS_BLOCKING(ec);
     }
 
+    if (ubf_th != Qfalse) {
+	thread_value(rb_thread_kill(ubf_th));
+    }
+
     errno = saved_errno;
 
     return val;
Index: ruby_2_6/thread_win32.c
===================================================================
--- ruby_2_6/thread_win32.c	(revision 66939)
+++ ruby_2_6/thread_win32.c	(revision 66940)
@@ -708,6 +708,12 @@ rb_thread_wakeup_timer_thread(int sig) https://github.com/ruby/ruby/blob/trunk/ruby_2_6/thread_win32.c#L708
     /* do nothing */
 }
 
+static VALUE
+rb_thread_start_unblock_thread(void)
+{
+    return Qfalse; /* no-op */
+}
+
 static void
 rb_thread_create_timer_thread(void)
 {
Index: ruby_2_6
===================================================================
--- ruby_2_6	(revision 66939)
+++ ruby_2_6	(revision 66940)

Property changes on: ruby_2_6
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r66708

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

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