all: remove thread_local feature
This commit is contained in:
parent
0c3c03b130
commit
53aa762239
9 changed files with 82 additions and 77 deletions
|
|
@ -27,26 +27,25 @@ pub static TEST_CONFIG_ENTRY: ConfigEntry = ConfigEntry {
|
|||
handle_msg,
|
||||
};
|
||||
|
||||
#[thread_local]
|
||||
static mut CONFIG: *const TestConfig = ptr::null();
|
||||
thread_local! {
|
||||
static CONFIG: Cell<*const TestConfig> = const { Cell::new(ptr::null()) };
|
||||
}
|
||||
|
||||
pub fn with_test_config<T, F>(f: F) -> T
|
||||
where
|
||||
F: FnOnce(Rc<TestConfig>) -> T,
|
||||
{
|
||||
unsafe {
|
||||
let tc = Rc::new(TestConfig {
|
||||
srv: Cell::new(None),
|
||||
responses: Default::default(),
|
||||
invoked_shortcuts: Default::default(),
|
||||
graphics_initialized: Cell::new(false),
|
||||
});
|
||||
let old = CONFIG;
|
||||
CONFIG = tc.deref();
|
||||
let res = f(tc.clone());
|
||||
CONFIG = old;
|
||||
res
|
||||
}
|
||||
let tc = Rc::new(TestConfig {
|
||||
srv: Cell::new(None),
|
||||
responses: Default::default(),
|
||||
invoked_shortcuts: Default::default(),
|
||||
graphics_initialized: Cell::new(false),
|
||||
});
|
||||
let old = CONFIG.get();
|
||||
CONFIG.set(tc.deref());
|
||||
let res = f(tc.clone());
|
||||
CONFIG.set(old);
|
||||
res
|
||||
}
|
||||
|
||||
unsafe extern "C" fn init(
|
||||
|
|
@ -56,7 +55,7 @@ unsafe extern "C" fn init(
|
|||
_msg: *const u8,
|
||||
_size: usize,
|
||||
) -> *const u8 {
|
||||
let tc = CONFIG;
|
||||
let tc = CONFIG.get();
|
||||
assert!(tc.is_not_null());
|
||||
Rc::increment_strong_count(tc);
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ use {
|
|||
|
||||
static LEVEL: AtomicUsize = AtomicUsize::new(Level::Info as usize);
|
||||
|
||||
#[thread_local]
|
||||
static FILE: CloneCell<Option<Rc<OwnedFd>>> = CloneCell::new(None);
|
||||
thread_local! {
|
||||
static FILE: CloneCell<Option<Rc<OwnedFd>>> = CloneCell::new(None);
|
||||
}
|
||||
|
||||
pub fn install() {
|
||||
log::set_logger(&Logger).unwrap();
|
||||
|
|
@ -27,11 +28,11 @@ pub fn set_level(level: Level) {
|
|||
}
|
||||
|
||||
pub fn set_file(file: Rc<OwnedFd>) {
|
||||
FILE.set(Some(file));
|
||||
FILE.with(|f| f.set(Some(file)));
|
||||
}
|
||||
|
||||
pub fn unset_file() {
|
||||
FILE.set(None);
|
||||
FILE.with(|f| f.set(None));
|
||||
}
|
||||
|
||||
struct Logger;
|
||||
|
|
@ -65,7 +66,7 @@ impl Log for Logger {
|
|||
record.args(),
|
||||
)
|
||||
};
|
||||
let mut fd = match FILE.get() {
|
||||
let mut fd = match FILE.with(|f| f.get()) {
|
||||
Some(f) => f.borrow(),
|
||||
_ => Fd::new(2),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue