Example #1
0
 Object* Thread::locals_remove(STATE, Symbol* key) {
   if(state->vm() != vm()) {
     return locals()->remove(state, key);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->remove(state, key);
   }
   if(fib->locals()->nil_p()) {
     return cNil;
   }
   return fib->locals()->remove(state, key);
 }
Example #2
0
  Fiber* Fiber::current(STATE) {
#ifdef RBX_FIBER_ENABLED
    Fiber* fib = state->vm()->current_fiber.get();

    // Lazily allocate a root fiber.
    if(fib->nil_p()) {
      fib = state->new_object<Fiber>(G(fiber));
      fib->prev(state, nil<Fiber>());
      fib->locals(state, nil<LookupTable>());
      fib->root_ = true;
      fib->status_ = Fiber::eRunning;

      fib->data_ = state->vm()->new_fiber_data(true);

      state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize);

      state->vm()->current_fiber.set(fib);
      state->vm()->root_fiber.set(fib);
    }

    return fib;
#else
    return nil<Fiber>();
#endif
  }
Example #3
0
 Object* Thread::locals_has_key(STATE, Symbol* key) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->has_key(state, key);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->has_key(state, key);
   }
   if(try_as<LookupTable>(fib->locals())) {
     return fib->locals()->has_key(state, key);
   }
   return cFalse;
 }
Example #4
0
 Array* Thread::locals_keys(STATE) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->all_keys(state);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->all_keys(state);
   }
   if(try_as<LookupTable>(fib->locals())) {
     return fib->locals()->all_keys(state);
   }
   return Array::create(state, 0);
 }
Example #5
0
 Object* Thread::locals_store(STATE, Symbol* key, Object* value) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->store(state, key, value);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->store(state, key, value);
   }
   if(fib->locals()->nil_p()) {
     fib->locals(state, LookupTable::create(state));
   }
   return fib->locals()->store(state, key, value);
 }
Example #6
0
  Fiber* Fiber::create(STATE, Object* self, Object* callable) {
#ifdef RBX_FIBER_ENABLED
    Fiber* fib = state->new_object<Fiber>(as<Class>(self));
    fib->starter(state, callable);
    fib->prev(state, nil<Fiber>());
    fib->locals(state, nil<LookupTable>());
    fib->root_ = false;
    fib->status_ = Fiber::eSleeping;

    fib->data_ = 0;

    state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize);

    return fib;
#else
    return static_cast<Fiber*>(Primitives::failure());
#endif
  }