Move script_runtime::StackRootTLS to root::ThreadLocalStackRoots

This commit is contained in:
Anthony Ramine 2017-09-27 13:58:59 +02:00
parent a6d01c92d9
commit 8d566fbc3c
6 changed files with 31 additions and 32 deletions

View file

@ -41,6 +41,7 @@ use std::default::Default;
use std::hash::{Hash, Hasher};
#[cfg(debug_assertions)]
use std::intrinsics::type_name;
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use std::ptr;
@ -165,6 +166,23 @@ impl Clone for RootCollectionPtr {
}
}
pub struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
impl<'a> ThreadLocalStackRoots<'a> {
pub fn new(roots: &'a RootCollection) -> Self {
STACK_ROOTS.with(|ref r| {
r.set(Some(RootCollectionPtr(roots as *const _)))
});
ThreadLocalStackRoots(PhantomData)
}
}
impl<'a> Drop for ThreadLocalStackRoots<'a> {
fn drop(&mut self) {
STACK_ROOTS.with(|ref r| r.set(None));
}
}
impl RootCollection {
/// Create an empty collection of roots
pub fn new() -> RootCollection {