struct TlsScopeGuard {
scope_ptr: NonNull<ProtectScope>,
}Expand description
Execute a closure with a new protection scope as the current TLS scope.
The scope is pushed onto the thread-local stack, the closure runs, and
then the scope is popped and dropped (triggering UNPROTECT(n)).
§Safety
Must be called from the R main thread.
§Example
ⓘ
unsafe fn my_call(x: SEXP) -> SEXP {
tls::with_protect_scope(|| {
let x = tls::protect(x);
let y = tls::protect(allocate_something());
combine(x.get(), y.get())
})
}Guard that pops the TLS scope stack on drop (panic-safe cleanup).
Fields§
§scope_ptr: NonNull<ProtectScope>Trait Implementations§
Auto Trait Implementations§
impl Freeze for TlsScopeGuard
impl !RefUnwindSafe for TlsScopeGuard
impl !Send for TlsScopeGuard
impl !Sync for TlsScopeGuard
impl Unpin for TlsScopeGuard
impl UnsafeUnpin for TlsScopeGuard
impl !UnwindSafe for TlsScopeGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more