From 00c04b92b91f89d99d50a0197bcc9ea39a1b1bf5 Mon Sep 17 00:00:00 2001 From: Brian Shirai Date: Fri, 15 May 2015 22:08:00 -0700 Subject: [PATCH] Cleaned up ThreadGroup. --- kernel/bootstrap/load_order.txt | 1 + kernel/bootstrap/thread.rb | 7 ++----- kernel/bootstrap/thread_mirror.rb | 9 ++++++++ kernel/common/load_order.txt | 1 + kernel/common/thread_group.rb | 31 +++++++++------------------- kernel/common/thread_group_mirror.rb | 13 ++++++++++++ vm/builtin/thread.cpp | 9 -------- vm/builtin/thread.hpp | 3 --- vm/capi/thread.cpp | 2 -- 9 files changed, 36 insertions(+), 40 deletions(-) create mode 100644 kernel/bootstrap/thread_mirror.rb create mode 100644 kernel/common/thread_group_mirror.rb diff --git a/kernel/bootstrap/load_order.txt b/kernel/bootstrap/load_order.txt index 3b8e70bd27..233e9c7301 100644 --- a/kernel/bootstrap/load_order.txt +++ b/kernel/bootstrap/load_order.txt @@ -44,6 +44,7 @@ stat.rbc string.rbc symbol.rbc thread.rbc +thread_mirror.rbc thunk.rbc time.rbc true.rbc diff --git a/kernel/bootstrap/thread.rb b/kernel/bootstrap/thread.rb index 59d724595c..f6121c411e 100644 --- a/kernel/bootstrap/thread.rb +++ b/kernel/bootstrap/thread.rb @@ -219,10 +219,6 @@ def group @group end - def add_to_group(group) - @group = group - end - def raise(exc=undefined, msg=nil, trace=nil) Rubinius.lock(self) @@ -377,7 +373,6 @@ def __run__ Rubinius.check_interrupts ensure unlock_locks - @joins.each { |join| join.send self } end end rescue Exception => e @@ -390,6 +385,8 @@ def __run__ end end + Rubinius::Mirror.reflect(@group).remove self + if Rubinius.thread_state[0] == :thread_kill @killed = true end diff --git a/kernel/bootstrap/thread_mirror.rb b/kernel/bootstrap/thread_mirror.rb new file mode 100644 index 0000000000..b7b5c95d30 --- /dev/null +++ b/kernel/bootstrap/thread_mirror.rb @@ -0,0 +1,9 @@ +module Rubinius + class Mirror + class Thread < Mirror + def group=(group) + Rubinius.invoke_primitive :object_set_ivar, @object, :@group, group + end + end + end +end diff --git a/kernel/common/load_order.txt b/kernel/common/load_order.txt index f218b5fdc3..95415dfb4b 100644 --- a/kernel/common/load_order.txt +++ b/kernel/common/load_order.txt @@ -80,6 +80,7 @@ symbol.rbc mutex.rbc thread.rbc thread_group.rbc +thread_group_mirror.rbc throw_catch.rbc time.rbc true.rbc diff --git a/kernel/common/thread_group.rb b/kernel/common/thread_group.rb index 8472082253..3f4d5d4170 100644 --- a/kernel/common/thread_group.rb +++ b/kernel/common/thread_group.rb @@ -7,34 +7,23 @@ def initialize Default = ThreadGroup.new def add(thread) - if thread.group - thread.group.remove(thread) - end - thread.add_to_group self + if g = thread.group + raise ThreadError, "can't move from the enclosed thread group" if g.enclosed? - @threads.delete_if do |w| - obj = w.__object__ - !(obj and obj.alive?) + gm = Rubinius::Mirror.reflect g + gm.remove thread end - @threads << WeakRef.new(thread) - self - end + tm = Rubinius::Mirror.reflect thread + tm.group = self - def remove(thread) - if enclosed? - raise ThreadError, "can't move from the enclosed thread group" - end - @threads.delete_if { |w| w.__object__ == thread } + @threads << thread + + self end def list - list = [] - @threads.each do |w| - obj = w.__object__ - list << obj if obj and obj.alive? - end - list + @threads end def enclose diff --git a/kernel/common/thread_group_mirror.rb b/kernel/common/thread_group_mirror.rb new file mode 100644 index 0000000000..776d903735 --- /dev/null +++ b/kernel/common/thread_group_mirror.rb @@ -0,0 +1,13 @@ +module Rubinius + class Mirror + class ThreadGroup < Mirror + self.subject = ::ThreadGroup + + def remove(thread) + ary = Rubinius.invoke_primitive :object_get_ivar, @object, :@threads + ary.delete thread + end + + end + end +end diff --git a/vm/builtin/thread.cpp b/vm/builtin/thread.cpp index 704b8e812c..590d6e86c0 100644 --- a/vm/builtin/thread.cpp +++ b/vm/builtin/thread.cpp @@ -72,7 +72,6 @@ namespace rubinius { thr->result(state, cFalse); thr->exception(state, nil()); thr->critical(state, cFalse); - thr->joins(state, Array::create(state, 1)); thr->killed(state, cFalse); thr->priority(state, Fixnum::from(0)); thr->pid(state, Fixnum::from(0)); @@ -474,14 +473,6 @@ namespace rubinius { return Location::mri_backtrace(state, cf); } - void Thread::release_joins(STATE, GCToken gct, CallFrame* calling_environment) { - for(native_int i = 0; i < joins_->size(); ++i) { - if(Channel* chn = try_as(joins_->get(state, i))) { - chn->send(state, gct, this, calling_environment); - } - } - } - void Thread::stopped() { alive_ = cFalse; } diff --git a/vm/builtin/thread.hpp b/vm/builtin/thread.hpp index cb303408cf..588cbe23a6 100644 --- a/vm/builtin/thread.hpp +++ b/vm/builtin/thread.hpp @@ -44,7 +44,6 @@ namespace rubinius { Object* result_; // slot Exception* exception_; // slot Object* critical_; // slot - Array* joins_; // slot Object* killed_; // slot Fixnum* priority_; // slot Fixnum* pid_; // slot @@ -86,7 +85,6 @@ namespace rubinius { attr_accessor(result, Object); attr_accessor(exception, Exception); attr_accessor(critical, Object); - attr_accessor(joins, Array); attr_accessor(killed, Object); attr_accessor(priority, Fixnum); attr_accessor(pid, Fixnum); @@ -271,7 +269,6 @@ namespace rubinius { void init_lock(); void stopped(); - void release_joins(STATE, GCToken gct, CallFrame* calling_environment); /** * Create a Thread object. diff --git a/vm/capi/thread.cpp b/vm/capi/thread.cpp index 1ba5aef12f..d6354c3285 100644 --- a/vm/capi/thread.cpp +++ b/vm/capi/thread.cpp @@ -294,7 +294,6 @@ extern "C" { self->hard_lock(state, gct, call_frame, false); Exception* exc = capi::c_as(self->current_exception(state)); self->exception(state, exc); - self->release_joins(state, gct, call_frame); self->alive(state, cFalse); self->hard_unlock(state, gct, call_frame); } @@ -314,7 +313,6 @@ extern "C" { OnStack<1> os(state, self); self->hard_lock(state, gct, &cf, false); - self->release_joins(state, gct, &cf); self->alive(state, cFalse); self->hard_unlock(state, gct, &cf);