VALUE rho_ruby_current_thread() { if ( ruby_native_thread_p() != 1 ) return 0; return rb_thread_current(); }
VALUE rho_ruby_current_thread() { if (!rho_ruby_is_started()) return 0; if ( ruby_native_thread_p() != 1 ) return 0; return rb_thread_current(); }
static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data) { struct gvl_callback cb; cb.closure = (Closure *) user_data; cb.retval = retval; cb.parameters = parameters; cb.done = false; if (rbffi_thread_has_gvl_p()) { callback_with_gvl(&cb); #if defined(HAVE_RUBY_NATIVE_THREAD_P) && defined (HAVE_RB_THREAD_CALL_WITH_GVL) } else if (ruby_native_thread_p()) { rb_thread_call_with_gvl(callback_with_gvl, &cb); #endif #if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32) } else { bool empty = false; pthread_mutex_init(&cb.async_mutex, NULL); pthread_cond_init(&cb.async_cond, NULL); // Now signal the async callback thread pthread_mutex_lock(&async_cb_mutex); empty = async_cb_list == NULL; cb.next = async_cb_list; async_cb_list = &cb; pthread_mutex_unlock(&async_cb_mutex); #if !defined(HAVE_RB_THREAD_BLOCKING_REGION) // Only signal if the list was empty if (empty) { char c; write(async_cb_pipe[1], &c, 1); } #else pthread_cond_signal(&async_cb_cond); #endif // Wait for the thread executing the ruby callback to signal it is done pthread_mutex_lock(&cb.async_mutex); while (!cb.done) { pthread_cond_wait(&cb.async_cond, &cb.async_mutex); } pthread_mutex_unlock(&cb.async_mutex); pthread_cond_destroy(&cb.async_cond); pthread_mutex_destroy(&cb.async_mutex); #elif defined(DEFER_ASYNC_CALLBACK) && defined(_WIN32) } else {