diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2017-09-19 12:03:49 -0700 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2017-09-19 13:04:30 -0700 |
commit | 531397ff15eed3da0839fc0029d48114c95bece2 (patch) | |
tree | 130b86e56b61fcb2ded2feda428ff5e6bb112ef8 /components/style/thread_state.rs | |
parent | b0d1cde558a0ecb8517974f8ef31c7d4f8b65770 (diff) | |
download | servo-531397ff15eed3da0839fc0029d48114c95bece2.tar.gz servo-531397ff15eed3da0839fc0029d48114c95bece2.zip |
Eliminate the now-unnecessary internal mod in thread_state.
MozReview-Commit-ID: 2d7lvQx7jOf
Diffstat (limited to 'components/style/thread_state.rs')
-rw-r--r-- | components/style/thread_state.rs | 85 |
1 files changed, 40 insertions, 45 deletions
diff --git a/components/style/thread_state.rs b/components/style/thread_state.rs index 035d1e939b8..3c06666a057 100644 --- a/components/style/thread_state.rs +++ b/components/style/thread_state.rs @@ -7,7 +7,7 @@ #![deny(missing_docs)] -pub use self::imp::{enter, exit, get, initialize}; +use std::cell::RefCell; bitflags! { /// A thread state flag, used for multiple assertions. @@ -50,53 +50,48 @@ thread_types! { is_layout = LAYOUT; } -mod imp { - use std::cell::RefCell; - use super::{TYPES, ThreadState}; +thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None)); - thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None)); - - /// Initialize the current thread state. - pub fn initialize(x: ThreadState) { - STATE.with(|ref k| { - if let Some(ref s) = *k.borrow() { - panic!("Thread state already initialized as {:?}", s); - } - *k.borrow_mut() = Some(x); - }); - get(); // check the assertion below - } +/// Initializes the current thread state. +pub fn initialize(x: ThreadState) { + STATE.with(|ref k| { + if let Some(ref s) = *k.borrow() { + panic!("Thread state already initialized as {:?}", s); + } + *k.borrow_mut() = Some(x); + }); + get(); // check the assertion below +} - /// Get the current thread state. - pub fn get() -> ThreadState { - let state = STATE.with(|ref k| { - match *k.borrow() { - // This is one of the layout threads, that use rayon. - None => super::LAYOUT | super::IN_WORKER, - Some(s) => s, - } - }); +/// Gets the current thread state. +pub fn get() -> ThreadState { + let state = STATE.with(|ref k| { + match *k.borrow() { + // This is one of the layout threads, that use rayon. + None => LAYOUT | 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()); - state - } + // Exactly one of the thread type flags should be set. + debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count()); + state +} - /// Enter into a given temporary state. Panics if re-entring. - pub fn enter(x: ThreadState) { - let state = get(); - debug_assert!(!state.intersects(x)); - STATE.with(|ref k| { - *k.borrow_mut() = Some(state | x); - }) - } +/// Enters into a given temporary state. Panics if re-entring. +pub fn enter(x: ThreadState) { + let state = get(); + debug_assert!(!state.intersects(x)); + STATE.with(|ref k| { + *k.borrow_mut() = Some(state | x); + }) +} - /// Exit a given temporary state. - pub fn exit(x: ThreadState) { - let state = get(); - debug_assert!(state.contains(x)); - STATE.with(|ref k| { - *k.borrow_mut() = Some(state & !x); - }) - } +/// Exits a given temporary state. +pub fn exit(x: ThreadState) { + let state = get(); + debug_assert!(state.contains(x)); + STATE.with(|ref k| { + *k.borrow_mut() = Some(state & !x); + }) } |