Skip to content

Commit

Permalink
* thread.c: rename methods:
Browse files Browse the repository at this point in the history
  from Thread.async_interrupt_timing to Thread.handle_interrupt,
  from Thread.async_interrupted? to Thread.pending_interrupt?.
  Also rename option from `defer' to `never'.
  [ruby-core:51074] [ruby-trunk - Feature ruby#6762]
* vm_core.c, thread.c: rename functions and data structure
  `async_errinfo' to `pending_interrupt'.
* thread.c: add global variables sym_immediate, sym_on_blocking and
  sym_never.
* cont.c, process.c, vm.c, signal.c: ditto.
* lib/sync.rb, lib/thread.rb: catch up this renaming.
* test/ruby/test_thread.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Dec 23, 2012
1 parent 80b5568 commit 0f9b33c
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 170 deletions.
20 changes: 20 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
Sun Dec 23 19:09:16 2012 Koichi Sasada <[email protected]>

* thread.c: rename methods:
from Thread.async_interrupt_timing to Thread.handle_interrupt,
from Thread.async_interrupted? to Thread.pending_interrupt?.
Also rename option from `defer' to `never'.
[ruby-core:51074] [ruby-trunk - Feature #6762]

* vm_core.c, thread.c: rename functions and data structure
`async_errinfo' to `pending_interrupt'.

* thread.c: add global variables sym_immediate, sym_on_blocking and
sym_never.

* cont.c, process.c, vm.c, signal.c: ditto.

* lib/sync.rb, lib/thread.rb: catch up this renaming.

* test/ruby/test_thread.rb: ditto.

Sun Dec 23 17:57:30 2012 Nobuyoshi Nakada <[email protected]>

* lib/profiler.rb (Profiler__::PROFILE_PROC, print_profile): store
Expand Down
4 changes: 2 additions & 2 deletions cont.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,12 +1162,12 @@ rb_fiber_start(void)

if (state) {
if (state == TAG_RAISE || state == TAG_FATAL) {
rb_threadptr_async_errinfo_enque(th, th->errinfo);
rb_threadptr_pending_interrupt_enque(th, th->errinfo);
}
else {
VALUE err = rb_vm_make_jump_tag_but_local_jump(state, th->errinfo);
if (!NIL_P(err))
rb_threadptr_async_errinfo_enque(th, err);
rb_threadptr_pending_interrupt_enque(th, err);
}
RUBY_VM_SET_INTERRUPT(th);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def sync_try_lock(mode = EX)

def sync_lock(m = EX)
return unlock if m == UN
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
while true
@sync_mutex.synchronize do
begin
Expand Down Expand Up @@ -227,7 +227,7 @@ def sync_unlock(m = EX)
end

def sync_synchronize(mode = EX)
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
sync_lock(mode)
begin
yield
Expand Down
14 changes: 7 additions & 7 deletions lib/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def initialize
# even if no other thread doesn't signal.
#
def wait(mutex, timeout=nil)
Thread.async_interrupt_timing(StandardError => :defer) do
Thread.handle_interrupt(StandardError => :never) do
begin
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
@waiters_mutex.synchronize do
@waiters[Thread.current] = true
end
Expand All @@ -84,7 +84,7 @@ def wait(mutex, timeout=nil)
# Wakes up the first thread in line waiting for this lock.
#
def signal
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
begin
t, _ = @waiters_mutex.synchronize { @waiters.shift }
t.run if t
Expand All @@ -99,7 +99,7 @@ def signal
# Wakes up all threads waiting for this lock.
#
def broadcast
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
threads = nil
@waiters_mutex.synchronize do
threads = @waiters.keys
Expand Down Expand Up @@ -160,7 +160,7 @@ def initialize
# Pushes +obj+ to the queue.
#
def push(obj)
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
@mutex.synchronize do
@que.push obj
@cond.signal
Expand All @@ -184,7 +184,7 @@ def push(obj)
# thread isn't suspended, and an exception is raised.
#
def pop(non_block=false)
Thread.async_interrupt_timing(StandardError => :on_blocking) do
Thread.handle_interrupt(StandardError => :on_blocking) do
@mutex.synchronize do
while true
if @que.empty?
Expand Down Expand Up @@ -300,7 +300,7 @@ def max=(max)
# until space becomes available.
#
def push(obj)
Thread.async_interrupt_timing(RuntimeError => :on_blocking) do
Thread.handle_interrupt(RuntimeError => :on_blocking) do
@mutex.synchronize do
while true
break if @que.length < @max
Expand Down
2 changes: 1 addition & 1 deletion process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ after_exec(void)
}

#define before_fork() before_exec()
#define after_fork() (rb_threadptr_async_errinfo_clear(GET_THREAD()), after_exec())
#define after_fork() (rb_threadptr_pending_interrupt_clear(GET_THREAD()), after_exec())

#include "dln.h"

Expand Down
2 changes: 1 addition & 1 deletion signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ signal_exec(VALUE cmd, int safe, int sig)
cur_th->interrupt_mask = old_interrupt_mask;

if (state) {
/* XXX: should be replaced with rb_threadptr_async_errinfo_enque() */
/* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */
JUMP_TAG(state);
}
}
Expand Down
48 changes: 24 additions & 24 deletions test/ruby/test_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ def test_no_valid_cfp
assert_equal("Can't call on top of Fiber or Thread", error.message, bug5083)
end

def make_async_interrupt_timing_test_thread1 flag
def make_handle_interrupt_test_thread1 flag
r = []
ready_p = false
th = Thread.new{
begin
Thread.async_interrupt_timing(RuntimeError => flag){
Thread.handle_interrupt(RuntimeError => flag){
begin
ready_p = true
sleep 0.5
Expand All @@ -543,46 +543,46 @@ def make_async_interrupt_timing_test_thread1 flag
r
end

def test_async_interrupt_timing
[[:defer, :c2],
def test_handle_interrupt
[[:never, :c2],
[:immediate, :c1],
[:on_blocking, :c1]].each{|(flag, c)|
assert_equal([flag, c], [flag] + make_async_interrupt_timing_test_thread1(flag))
assert_equal([flag, c], [flag] + make_handle_interrupt_test_thread1(flag))
}
# TODO: complex cases are needed.
end

def test_async_interrupt_timing_invalid_argument
def test_handle_interrupt_invalid_argument
assert_raise(ArgumentError) {
Thread.async_interrupt_timing(RuntimeError => :immediate) # no block
Thread.handle_interrupt(RuntimeError => :immediate) # no block
}
assert_raise(ArgumentError) {
Thread.async_interrupt_timing(RuntimeError => :never) {} # never?
Thread.handle_interrupt(RuntimeError => :xyzzy) {}
}
assert_raise(TypeError) {
Thread.async_interrupt_timing([]) {} # array
Thread.handle_interrupt([]) {} # array
}
end

def for_test_async_interrupt_with_return
Thread.async_interrupt_timing(Object => :defer){
def for_test_handle_interrupt_with_return
Thread.handle_interrupt(Object => :never){
Thread.current.raise RuntimeError.new("have to be rescured")
return
}
rescue
end

def test_async_interrupt_with_return
def test_handle_interrupt_with_return
assert_nothing_raised do
for_test_async_interrupt_with_return
for_test_handle_interrupt_with_return
_dummy_for_check_ints=nil
end
end

def test_async_interrupt_with_break
def test_handle_interrupt_with_break
assert_nothing_raised do
begin
Thread.async_interrupt_timing(Object => :defer){
Thread.handle_interrupt(Object => :never){
Thread.current.raise RuntimeError.new("have to be rescured")
break
}
Expand All @@ -592,13 +592,13 @@ def test_async_interrupt_with_break
end
end

def test_async_interrupt_blocking
def test_handle_interrupt_blocking
r=:ng
e=Class.new(Exception)
th_s = Thread.current
begin
th = Thread.start{
Thread.async_interrupt_timing(Object => :on_blocking){
Thread.handle_interrupt(Object => :on_blocking){
begin
Thread.current.raise RuntimeError
r=:ok
Expand All @@ -617,12 +617,12 @@ def test_async_interrupt_blocking
assert_equal(:ok,r)
end

def test_async_interrupt_and_io
def test_handle_interrupt_and_io
assert_in_out_err([], <<-INPUT, %w(ok), [])
th_waiting = true
t = Thread.new {
Thread.async_interrupt_timing(RuntimeError => :on_blocking) {
Thread.handle_interrupt(RuntimeError => :on_blocking) {
nil while th_waiting
# async interrupt should be raised _before_ writing puts arguments
puts "ng"
Expand All @@ -637,12 +637,12 @@ def test_async_interrupt_and_io
INPUT
end

def test_async_interrupt_and_p
def test_handle_interrupt_and_p
assert_in_out_err([], <<-INPUT, %w(:ok :ok), [])
th_waiting = true
t = Thread.new {
Thread.async_interrupt_timing(RuntimeError => :on_blocking) {
Thread.handle_interrupt(RuntimeError => :on_blocking) {
nil while th_waiting
# p shouldn't provide interruptible point
p :ok
Expand All @@ -657,9 +657,9 @@ def test_async_interrupt_and_p
INPUT
end

def test_async_interrupted?
def test_handle_interrupted?
q = Queue.new
Thread.async_interrupt_timing(RuntimeError => :defer){
Thread.handle_interrupt(RuntimeError => :never){
th = Thread.new{
q.push :e
begin
Expand All @@ -669,7 +669,7 @@ def test_async_interrupted?
q.push :ng1
end
begin
Thread.async_interrupt_timing(Object => :immediate){} if Thread.async_interrupted?
Thread.handle_interrupthandle_interrupt(Object => :immediate){} if Thread.pending_interrupt?
rescue => e
q.push :ok
end
Expand Down
Loading

0 comments on commit 0f9b33c

Please sign in to comment.