Esempio n. 1
0
 void Fiber::unpack_arguments(STATE, Arguments& args) {
   switch(args.total()) {
     case 0:
       state->vm()->thread()->fiber_value(state, cNil);
       break;
     case 1:
       state->vm()->thread()->fiber_value(state, args.get_argument(0));
       break;
     default:
       state->vm()->thread()->fiber_value(state,  args.as_array(state));
       break;
   }
 }
Esempio n. 2
0
  void Fiber::start(STATE, Arguments& args) {
    state->vm()->thread()->fiber_value(state, args.as_array(state));

    pthread_attr_t attrs;
    pthread_attr_init(&attrs);
    pthread_attr_setstacksize(&attrs, stack_size()->to_native());
    pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);

    int status = pthread_create(&vm()->os_thread(), &attrs,
        Fiber::run, (void*)vm());

    pthread_attr_destroy(&attrs);

    if(status != 0) {
      char buf[RBX_STRERROR_BUFSIZE];
      char* err = RBX_STRERROR(status, buf, RBX_STRERROR_BUFSIZE);
      Exception::raise_fiber_error(state, err);
    }

    // Wait for Fiber thread to start up and pause.
    while(!vm()->suspended_p()) {
      ; // spin wait
    }
  }