Esempio n. 1
0
  // THAR BE DRAGONS.
  //
  // When venturing through the valleys of the unmanaged, our hero must
  // remain vigilant and disiplined! If she should ever find a VALUE for
  // a reference in her travels: Look away! For these VALUEs are pure
  // death! Our hero must steel herself and continue on her quest, returning
  // as soon as possible to the castle of the managed.
  VALUE rb_thread_blocking_region(rb_blocking_function_t func, void* data,
                                  rb_unblock_function_t ubf, void* ubf_data) {
    NativeMethodEnvironment* env = NativeMethodEnvironment::get();
    VM* state = env->state();
    UnblockFuncWaiter waiter(ubf, ubf_data);
    VALUE ret = Qnil;

    if (ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
      state->interrupt_with_signal();
    } else {
      state->install_waiter(waiter);
    }
    {
      GlobalLock::UnlockGuard guard(env);
      ret = (*func)(data);
    }
    state->clear_waiter();

    return ret;
  }