refact: Remove gc_registering_current_thread

Closes #31

A guard object is more capable, as it can be used in various
control flow and ownership schemes, including async code, but not
that it is not Send.

(cherry picked from commit f9aa5eab2561834c64ef9fe01979a91aee35848f)
This commit is contained in:
Robert Hensing 2024-10-16 12:14:37 +02:00
parent ad0f5d0240
commit 4eade817b6

View file

@ -483,17 +483,6 @@ impl Drop for ThreadRegistrationGuard {
}
}
/// Run a function while making sure that the current thread is registered with the GC.
pub fn gc_registering_current_thread<F, R>(f: F) -> Result<R>
where
F: FnOnce() -> R,
{
let guard = gc_register_my_thread()?;
let r = f();
drop(guard);
Ok(r)
}
fn gc_register_my_thread_do_it() -> Result<()> {
unsafe {
let mut sb: raw::GC_stack_base = raw::GC_stack_base {
@ -566,6 +555,17 @@ mod tests {
test_init();
}
/// Run a function while making sure that the current thread is registered with the GC.
pub fn gc_registering_current_thread<F, R>(f: F) -> Result<R>
where
F: FnOnce() -> R,
{
let guard = gc_register_my_thread()?;
let r = f();
drop(guard);
Ok(r)
}
#[test]
fn eval_state_new_and_drop() {
gc_registering_current_thread(|| {