Eliminate the now-unnecessary internal mod in thread_state.

MozReview-Commit-ID: 2d7lvQx7jOf
This commit is contained in:
Bobby Holley 2017-09-19 12:03:49 -07:00
parent b0d1cde558
commit 531397ff15

View file

@ -7,7 +7,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
pub use self::imp::{enter, exit, get, initialize}; use std::cell::RefCell;
bitflags! { bitflags! {
/// A thread state flag, used for multiple assertions. /// A thread state flag, used for multiple assertions.
@ -50,53 +50,48 @@ thread_types! {
is_layout = LAYOUT; is_layout = LAYOUT;
} }
mod imp { thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None));
use std::cell::RefCell;
use super::{TYPES, ThreadState};
thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None)); /// Initializes the current thread state.
pub fn initialize(x: ThreadState) {
/// Initialize the current thread state. STATE.with(|ref k| {
pub fn initialize(x: ThreadState) { if let Some(ref s) = *k.borrow() {
STATE.with(|ref k| { panic!("Thread state already initialized as {:?}", s);
if let Some(ref s) = *k.borrow() { }
panic!("Thread state already initialized as {:?}", s); *k.borrow_mut() = Some(x);
} });
*k.borrow_mut() = Some(x); get(); // check the assertion below
}); }
get(); // check the assertion below
} /// Gets the current thread state.
pub fn get() -> ThreadState {
/// Get the current thread state. let state = STATE.with(|ref k| {
pub fn get() -> ThreadState { match *k.borrow() {
let state = STATE.with(|ref k| { // This is one of the layout threads, that use rayon.
match *k.borrow() { None => LAYOUT | IN_WORKER,
// This is one of the layout threads, that use rayon. Some(s) => s,
None => super::LAYOUT | super::IN_WORKER, }
Some(s) => s, });
}
}); // Exactly one of the thread type flags should be set.
debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count());
// Exactly one of the thread type flags should be set. state
debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count()); }
state
} /// Enters into a given temporary state. Panics if re-entring.
pub fn enter(x: ThreadState) {
/// Enter into a given temporary state. Panics if re-entring. let state = get();
pub fn enter(x: ThreadState) { debug_assert!(!state.intersects(x));
let state = get(); STATE.with(|ref k| {
debug_assert!(!state.intersects(x)); *k.borrow_mut() = Some(state | x);
STATE.with(|ref k| { })
*k.borrow_mut() = Some(state | x); }
})
} /// Exits a given temporary state.
pub fn exit(x: ThreadState) {
/// Exit a given temporary state. let state = get();
pub fn exit(x: ThreadState) { debug_assert!(state.contains(x));
let state = get(); STATE.with(|ref k| {
debug_assert!(state.contains(x)); *k.borrow_mut() = Some(state & !x);
STATE.with(|ref k| { })
*k.borrow_mut() = Some(state & !x);
})
}
} }