From 4eade817b6c458a9d49a7e63fc760ca7a8e3d5da Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 16 Oct 2024 12:14:37 +0200 Subject: [PATCH] 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) --- rust/nix-expr/src/eval_state.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/nix-expr/src/eval_state.rs b/rust/nix-expr/src/eval_state.rs index 6a3718b..de5550f 100644 --- a/rust/nix-expr/src/eval_state.rs +++ b/rust/nix-expr/src/eval_state.rs @@ -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: F) -> Result -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: F) -> Result + 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(|| {