Skip to content

Commit

Permalink
Auto merge of #6494 - Ms2ger:atomic, r=metajack
Browse files Browse the repository at this point in the history
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).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6494)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jun 27, 2015
2 parents 9c5eb16 + 0d0c8f2 commit 8892f81
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions components/util/opts.rs
Expand Up @@ -21,6 +21,7 @@ use std::mem;
use std::path::Path;
use std::process;
use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
use url::{self, Url};

/// Global flags for Servo, currently set on the command line.
Expand Down Expand Up @@ -422,21 +423,17 @@ pub fn from_cmdline_args(args: &[String]) {
set(opts);
}

static mut EXPERIMENTAL_ENABLED: bool = false;
static EXPERIMENTAL_ENABLED: AtomicBool = ATOMIC_BOOL_INIT;

/// Turn on experimental features globally. Normally this is done
/// during initialization by `set` or `from_cmdline_args`, but
/// tests that require experimental features will also set it.
pub fn set_experimental_enabled(new_value: bool) {
unsafe {
EXPERIMENTAL_ENABLED = new_value;
}
EXPERIMENTAL_ENABLED.store(new_value, Ordering::SeqCst);
}

pub fn experimental_enabled() -> bool {
unsafe {
EXPERIMENTAL_ENABLED
}
EXPERIMENTAL_ENABLED.load(Ordering::SeqCst)
}

// Make Opts available globally. This saves having to clone and pass
Expand Down

0 comments on commit 8892f81

Please sign in to comment.