Skip to content

Commit

Permalink
Reference current Fiber from Thread.
Browse files Browse the repository at this point in the history
brixen committed Jun 18, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4029f06 commit d2930b5
Showing 6 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ namespace rubinius {
void Fiber::restart(STATE) {
std::lock_guard<std::mutex> guard(state->vm()->thread()->fiber_mutex());

state->vm()->thread()->vm()->set_current_fiber(vm());
state->vm()->thread()->current_fiber(state, this);

while(vm()->wait_flag()) {
std::lock_guard<std::mutex> guard(vm()->wait_mutex());
24 changes: 12 additions & 12 deletions machine/builtin/thread.cpp
Original file line number Diff line number Diff line change
@@ -76,8 +76,8 @@ namespace rubinius {

vm->set_thread(thr);

Fiber::create(state, vm);
vm->set_current_fiber(vm->fiber()->vm());
thr->fiber(state, Fiber::create(state, vm));
thr->current_fiber(state, thr->fiber());

return thr;
}
@@ -265,20 +265,20 @@ namespace rubinius {
}

Object* Thread::fiber_variable_get(STATE, Symbol* key) {
return state->vm()->fiber()->locals()->aref(state, key);
return current_fiber()->locals()->aref(state, key);
}

Object* Thread::fiber_variable_set(STATE, Symbol* key, Object* value) {
check_frozen(state);
return state->vm()->fiber()->locals()->store(state, key, value);
return current_fiber()->locals()->store(state, key, value);
}

Object* Thread::fiber_variable_key_p(STATE, Symbol* key) {
return state->vm()->fiber()->locals()->has_key(state, key);
return current_fiber()->locals()->has_key(state, key);
}

Array* Thread::fiber_variables(STATE) {
return state->vm()->fiber()->locals()->all_keys(state);
return current_fiber()->locals()->all_keys(state);
}

int Thread::start_thread(STATE, void* (*function)(void*)) {
@@ -440,8 +440,8 @@ namespace rubinius {

if(!vm()) return cNil;

vm()->current_fiber()->register_kill(state);
vm()->current_fiber()->wakeup(state);
current_fiber()->vm()->register_kill(state);
current_fiber()->vm()->wakeup(state);

return exc;
}
@@ -452,11 +452,11 @@ namespace rubinius {
if(!vm()) return cNil;

if(state->vm()->thread() == this) {
vm()->current_fiber()->thread_state()->raise_thread_kill();
current_fiber()->vm()->thread_state()->raise_thread_kill();
return NULL;
} else {
vm()->current_fiber()->register_kill(state);
vm()->current_fiber()->wakeup(state);
current_fiber()->vm()->register_kill(state);
current_fiber()->vm()->wakeup(state);
return this;
}
}
@@ -468,7 +468,7 @@ namespace rubinius {
return force_as<Thread>(Primitives::failure());
}

vm()->current_fiber()->wakeup(state);
current_fiber()->vm()->wakeup(state);

return this;
}
6 changes: 2 additions & 4 deletions machine/builtin/thread.hpp
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ namespace rubinius {
attr_accessor(stack_size, Fixnum);
attr_accessor(source, String);
attr_accessor(fiber, Fiber);
attr_accessor(current_fiber, Fiber);

private:
utilities::thread::SpinLock init_lock_;
@@ -58,10 +59,6 @@ namespace rubinius {
/// The VM state for this thread and this thread alone
attr_field(vm, VM*);

typedef std::list<Fiber*> FibersList;

attr_field(fibers, FibersList);

typedef Object* (*ThreadFunction)(STATE);

attr_field(function, ThreadFunction);
@@ -89,6 +86,7 @@ namespace rubinius {
obj->stack_size(Fixnum::from(state->shared().config.machine_thread_stack_size.value));
obj->source(nil<String>());
obj->fiber(nil<Fiber>());
obj->current_fiber(nil<Fiber>());

obj->init_lock_.init();
obj->join_lock_.init();
5 changes: 2 additions & 3 deletions machine/stack_variables.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

#include "builtin/fiber.hpp"
#include "builtin/lookup_table.hpp"
#include "builtin/thread.hpp"
#include "builtin/variable_scope.hpp"

namespace rubinius {
@@ -31,9 +32,7 @@ namespace rubinius {
scope->method(state, call_frame->compiled_code);
scope->heap_locals(state, nil<Tuple>());
scope->last_match(state, last_match_);
/* TODO: Fiber
scope->fiber(state, state->vm()->current_fiber.get());
*/
scope->fiber(state, state->vm()->thread()->current_fiber());

scope->number_of_locals(mcode->number_of_locals);
scope->isolated(0);
1 change: 0 additions & 1 deletion machine/vm.cpp
Original file line number Diff line number Diff line change
@@ -91,7 +91,6 @@ namespace rubinius {
, interrupted_exception_(this, nil<Exception>())
, thread_(this, nil<Thread>())
, fiber_(this, nil<Fiber>())
, current_fiber_(NULL)
, waiting_object_(this, cNil)
, start_time_(0)
, native_method_environment(NULL)
10 changes: 0 additions & 10 deletions machine/vm.hpp
Original file line number Diff line number Diff line change
@@ -136,8 +136,6 @@ namespace rubinius {
memory::TypedRoot<Thread*> thread_;
memory::TypedRoot<Fiber*> fiber_;

VM* current_fiber_;

/// Object that waits for inflation
memory::TypedRoot<Object*> waiting_object_;

@@ -192,14 +190,6 @@ namespace rubinius {
wait_flag_ = wait;
}

void set_current_fiber(VM* vm) {
current_fiber_ = vm;
}

VM* current_fiber() {
return current_fiber_;
}

void set_thread(Thread* thread);
void set_fiber(Fiber* fiber);

0 comments on commit d2930b5

Please sign in to comment.