summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 18:07:08 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 18:07:08 +0000
commitd014f463cf6d5dd51aa2ce56385fc08ac5c121af (patch)
tree7d41c2db84af1220161c42569fce993b1b957c21
parented20b2561ce9a387da6de5f93a7b7931cd136efd (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/thread/thread.c3
-rw-r--r--test/thread/test_queue.rb17
-rw-r--r--thread.c15
-rw-r--r--version.h2
4 files changed, 31 insertions, 6 deletions
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index b8656a1d97..2a2db3f760 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -269,7 +269,8 @@ queue_delete_from_waiting(struct waiting_delete *p)
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;
}
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index 2bd71dbfc9..32c740277a 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -277,4 +277,21 @@ class TestQueue < Test::Unit::TestCase
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
diff --git a/thread.c b/thread.c
index 046364dfe5..09765e5cad 100644
--- a/thread.c
+++ b/thread.c
@@ -830,7 +830,7 @@ thread_join_sleep(VALUE arg)
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
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)
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;
}
diff --git a/version.h b/version.h
index e14d8b6564..86dd75ae77 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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