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

ruby-changes:46044

From: usa <ko1@a...>
Date: Sun, 26 Mar 2017 03:07:16 +0900 (JST)
Subject: [ruby-changes:46044] usa:r58115 (ruby_2_2): merge revision(s) 57477, 57478, 57479, 57492: [Backport #12405]

usa	2017-03-26 03:07:08 +0900 (Sun, 26 Mar 2017)

  New Revision: 58115

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

  Log:
    merge revision(s) 57477,57478,57479,57492: [Backport #12405]
    
    use TRUE/FALSE.
    
    define rb_thread_sleep_deadly_allow_spurious_wakeup().
    
    * thread.c, thread_sync.c: define new function
      rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
      using sleep_forever() directly.
    
    allow Queue operation in trap.
    
    * thread_sync.c: allow spurious wakeup to check Queue status just after trap.
      [Bug #12405]
    
    * test/thread/test_queue.rb: add a test for it.
    
    test_queue.rb: fix portability
    
    * test/thread/test_queue.rb (test_queue_with_trap): fix
      portability.  use SIGINT instead of SIGUSR2 which is supported
      on not all platforms.

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ext/thread/thread.c
    branches/ruby_2_2/test/thread/test_queue.rb
    branches/ruby_2_2/thread.c
    branches/ruby_2_2/version.h
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 58114)
+++ ruby_2_2/version.h	(revision 58115)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.7"
 #define RUBY_RELEASE_DATE "2017-03-26"
-#define RUBY_PATCHLEVEL 447
+#define RUBY_PATCHLEVEL 448
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_2/test/thread/test_queue.rb
===================================================================
--- ruby_2_2/test/thread/test_queue.rb	(revision 58114)
+++ ruby_2_2/test/thread/test_queue.rb	(revision 58115)
@@ -277,4 +277,21 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/thread/test_queue.rb#L277
       Marshal.dump(q)
     end
   end
+
+  def test_queue_with_trap
+    assert_in_out_err([], <<-INPUT, %w(INT INT exit), [])
+      q = Queue.new
+      trap(:INT){
+        q.push 'INT'
+      }
+      Thread.new{
+        loop{
+          Process.kill :INT, $$
+        }
+      }
+      puts q.pop
+      puts q.pop
+      puts 'exit'
+    INPUT
+  end
 end
Index: ruby_2_2/thread.c
===================================================================
--- ruby_2_2/thread.c	(revision 58114)
+++ ruby_2_2/thread.c	(revision 58115)
@@ -830,7 +830,7 @@ thread_join_sleep(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/thread.c#L830
 
     while (target_th->status != THREAD_KILLED) {
 	if (p->forever) {
-	    sleep_forever(th, 1, 0);
+	    sleep_forever(th, TRUE, FALSE);
 	}
 	else {
 	    now = timeofday();
@@ -1117,14 +1117,21 @@ void https://github.com/ruby/ruby/blob/trunk/ruby_2_2/thread.c#L1117
 rb_thread_sleep_forever(void)
 {
     thread_debug("rb_thread_sleep_forever\n");
-    sleep_forever(GET_THREAD(), 0, 1);
+    sleep_forever(GET_THREAD(), FALSE, TRUE);
 }
 
 void
 rb_thread_sleep_deadly(void)
 {
     thread_debug("rb_thread_sleep_deadly\n");
-    sleep_forever(GET_THREAD(), 1, 1);
+    sleep_forever(GET_THREAD(), TRUE, TRUE);
+}
+
+void
+rb_thread_sleep_deadly_allow_spurious_wakeup(void)
+{
+    thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n");
+    sleep_forever(GET_THREAD(), TRUE, FALSE);
 }
 
 static double
@@ -4507,7 +4514,7 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes https://github.com/ruby/ruby/blob/trunk/ruby_2_2/thread.c#L4514
 static VALUE
 rb_mutex_sleep_forever(VALUE time)
 {
-    sleep_forever(GET_THREAD(), 1, 0); /* permit spurious check */
+    rb_thread_sleep_deadly_allow_spurious_wakeup();
     return Qnil;
 }
 
Index: ruby_2_2/ext/thread/thread.c
===================================================================
--- ruby_2_2/ext/thread/thread.c	(revision 58114)
+++ ruby_2_2/ext/thread/thread.c	(revision 58115)
@@ -269,7 +269,8 @@ queue_delete_from_waiting(struct waiting https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/thread/thread.c#L269
 static VALUE
 queue_sleep(VALUE arg)
 {
-    rb_thread_sleep_deadly();
+    extern void rb_thread_sleep_deadly_allow_spurious_wakeup(void);
+    rb_thread_sleep_deadly_allow_spurious_wakeup();
     return Qnil;
 }
 

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57477,57492


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

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