Sha256: de4d30ffd28e9a9b76e7b733d9a327819ddefb4b8caef8f7c8dfbd03117de418

Contents?: true

Size: 702 Bytes

Versions: 16

Compression:

Stored size: 702 Bytes

Contents

use std::{ffi::c_void, mem::MaybeUninit, ptr::null_mut};

use rb_sys::rb_thread_call_without_gvl;

unsafe extern "C" fn call_without_gvl<F, R>(arg: *mut c_void) -> *mut c_void
where
    F: FnMut() -> R,
    R: Sized,
{
    let arg = arg as *mut (&mut F, &mut MaybeUninit<R>);
    let (func, result) = unsafe { &mut *arg };
    result.write(func());

    null_mut()
}

pub fn nogvl<F, R>(mut func: F) -> R
where
    F: FnMut() -> R,
    R: Sized,
{
    let result = MaybeUninit::uninit();
    let arg_ptr = &(&mut func, &result) as *const _ as *mut c_void;

    unsafe {
        rb_thread_call_without_gvl(Some(call_without_gvl::<F, R>), arg_ptr, None, null_mut());
        result.assume_init()
    }
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ext/src/helpers/nogvl.rs
wasmtime-28.0.0 ext/src/helpers/nogvl.rs
wasmtime-27.0.0 ext/src/helpers/nogvl.rs
wasmtime-26.0.0 ext/src/helpers/nogvl.rs
wasmtime-25.0.2 ext/src/helpers/nogvl.rs
wasmtime-25.0.1 ext/src/helpers/nogvl.rs
wasmtime-25.0.0 ext/src/helpers/nogvl.rs
wasmtime-24.0.0 ext/src/helpers/nogvl.rs
wasmtime-23.0.2 ext/src/helpers/nogvl.rs
wasmtime-22.0.0 ext/src/helpers/nogvl.rs
wasmtime-21.0.1 ext/src/helpers/nogvl.rs
wasmtime-20.0.2 ext/src/helpers/nogvl.rs
wasmtime-20.0.0 ext/src/helpers/nogvl.rs
wasmtime-18.0.3 ext/src/helpers/nogvl.rs
wasmtime-17.0.1 ext/src/helpers/nogvl.rs
wasmtime-17.0.0 ext/src/helpers/nogvl.rs