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,14 +50,10 @@ 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.
pub fn initialize(x: ThreadState) {
STATE.with(|ref k| { STATE.with(|ref k| {
if let Some(ref s) = *k.borrow() { if let Some(ref s) = *k.borrow() {
panic!("Thread state already initialized as {:?}", s); panic!("Thread state already initialized as {:?}", s);
@ -65,14 +61,14 @@ mod imp {
*k.borrow_mut() = Some(x); *k.borrow_mut() = Some(x);
}); });
get(); // check the assertion below get(); // check the assertion below
} }
/// Get the current thread state. /// Gets the current thread state.
pub fn get() -> ThreadState { pub fn get() -> ThreadState {
let state = STATE.with(|ref k| { let state = STATE.with(|ref k| {
match *k.borrow() { match *k.borrow() {
// This is one of the layout threads, that use rayon. // This is one of the layout threads, that use rayon.
None => super::LAYOUT | super::IN_WORKER, None => LAYOUT | IN_WORKER,
Some(s) => s, Some(s) => s,
} }
}); });
@ -80,23 +76,22 @@ mod imp {
// Exactly one of the thread type flags should be set. // Exactly one of the thread type flags should be set.
debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count()); debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count());
state state
} }
/// Enter into a given temporary state. Panics if re-entring. /// Enters into a given temporary state. Panics if re-entring.
pub fn enter(x: ThreadState) { pub fn enter(x: ThreadState) {
let state = get(); let state = get();
debug_assert!(!state.intersects(x)); debug_assert!(!state.intersects(x));
STATE.with(|ref k| { STATE.with(|ref k| {
*k.borrow_mut() = Some(state | x); *k.borrow_mut() = Some(state | x);
}) })
} }
/// Exit a given temporary state. /// Exits a given temporary state.
pub fn exit(x: ThreadState) { pub fn exit(x: ThreadState) {
let state = get(); let state = get();
debug_assert!(state.contains(x)); debug_assert!(state.contains(x));
STATE.with(|ref k| { STATE.with(|ref k| {
*k.borrow_mut() = Some(state & !x); *k.borrow_mut() = Some(state & !x);
}) })
}
} }