mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Use an atomic bool for EXPERIMENTAL_ENABLED.
static mut smells, especially as it can be set and read from multiple threads (for example in unit tests).
This commit is contained in:
parent
b73eca160c
commit
0d0c8f2d42
1 changed files with 4 additions and 7 deletions
|
@ -21,6 +21,7 @@ use std::mem;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
|
||||||
use url::{self, Url};
|
use url::{self, Url};
|
||||||
|
|
||||||
/// Global flags for Servo, currently set on the command line.
|
/// Global flags for Servo, currently set on the command line.
|
||||||
|
@ -422,21 +423,17 @@ pub fn from_cmdline_args(args: &[String]) {
|
||||||
set(opts);
|
set(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut EXPERIMENTAL_ENABLED: bool = false;
|
static EXPERIMENTAL_ENABLED: AtomicBool = ATOMIC_BOOL_INIT;
|
||||||
|
|
||||||
/// Turn on experimental features globally. Normally this is done
|
/// Turn on experimental features globally. Normally this is done
|
||||||
/// during initialization by `set` or `from_cmdline_args`, but
|
/// during initialization by `set` or `from_cmdline_args`, but
|
||||||
/// tests that require experimental features will also set it.
|
/// tests that require experimental features will also set it.
|
||||||
pub fn set_experimental_enabled(new_value: bool) {
|
pub fn set_experimental_enabled(new_value: bool) {
|
||||||
unsafe {
|
EXPERIMENTAL_ENABLED.store(new_value, Ordering::SeqCst);
|
||||||
EXPERIMENTAL_ENABLED = new_value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn experimental_enabled() -> bool {
|
pub fn experimental_enabled() -> bool {
|
||||||
unsafe {
|
EXPERIMENTAL_ENABLED.load(Ordering::SeqCst)
|
||||||
EXPERIMENTAL_ENABLED
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make Opts available globally. This saves having to clone and pass
|
// Make Opts available globally. This saves having to clone and pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue