Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 433d9b8c4ce3
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3adb3559176c
Choose a head ref
  • 2 commits
  • 11 files changed
  • 1 contributor

Commits on May 16, 2015

  1. Cleaned up ThreadGroup.

    brixen committed May 16, 2015
    3
    Copy the full SHA
    00c04b9 View commit details
  2. Copy the full SHA
    3adb355 View commit details
1 change: 1 addition & 0 deletions kernel/bootstrap/load_order.txt
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ stat.rbc
string.rbc
symbol.rbc
thread.rbc
thread_mirror.rbc
thunk.rbc
time.rbc
true.rbc
7 changes: 2 additions & 5 deletions kernel/bootstrap/thread.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions kernel/bootstrap/thread_mirror.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions kernel/common/load_order.txt
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ symbol.rbc
mutex.rbc
thread.rbc
thread_group.rbc
thread_group_mirror.rbc
throw_catch.rbc
time.rbc
true.rbc
31 changes: 10 additions & 21 deletions kernel/common/thread_group.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions kernel/common/thread_group_mirror.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 0 additions & 9 deletions vm/builtin/thread.cpp
Original file line number Diff line number Diff line change
@@ -72,7 +72,6 @@ namespace rubinius {
thr->result(state, cFalse);
thr->exception(state, nil<Exception>());
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<Channel>(joins_->get(state, i))) {
chn->send(state, gct, this, calling_environment);
}
}
}

void Thread::stopped() {
alive_ = cFalse;
}
3 changes: 0 additions & 3 deletions vm/builtin/thread.hpp
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 0 additions & 2 deletions vm/capi/thread.cpp
Original file line number Diff line number Diff line change
@@ -294,7 +294,6 @@ extern "C" {
self->hard_lock(state, gct, call_frame, false);
Exception* exc = capi::c_as<Exception>(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);

15 changes: 11 additions & 4 deletions vm/gc/finalize.cpp
Original file line number Diff line number Diff line change
@@ -286,7 +286,7 @@ namespace rubinius {
i->queued();
}

queue_objects();
queue_objects(state);
}

first_process_item();
@@ -370,15 +370,22 @@ namespace rubinius {
live_list_->push_front(fi);
}

void FinalizerThread::queue_objects() {
void FinalizerThread::queue_objects(STATE) {
if(live_list_->empty()) return;

FinalizeObjects* dead_list = new FinalizeObjects();

for(FinalizeObjects::iterator i = live_list_->begin();
i != live_list_->end();
/* advance is handled in the loop */)
{
if(i->queued_p()) {
dead_list->push_front(*i);
if(i->kind == FinalizeObject::eUnmanaged && !i->ruby_finalizer) {
i->finalizer(state, i->object);
} else {
dead_list->push_front(*i);
}

i = live_list_->erase(i);
} else {
++i;
@@ -402,7 +409,7 @@ namespace rubinius {
}

void FinalizerThread::finish_collection(STATE) {
queue_objects();
queue_objects(state);

if(iterator_) {
delete iterator_;
2 changes: 1 addition & 1 deletion vm/gc/finalize.hpp
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ namespace rubinius {
void record(Object* obj, FinalizerFunction func, FinalizeObject::FinalizeKind kind);
void set_ruby_finalizer(Object* obj, Object* finalizer);

void queue_objects();
void queue_objects(STATE);

void start_collection(STATE);
void finish_collection(STATE);