From 0d0c8f2d420bb30dad4d7c15a716f82986d39386 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 27 Jun 2015 09:06:45 +0200 Subject: [PATCH] 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). --- components/util/opts.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/util/opts.rs b/components/util/opts.rs index 3c5be3888bb..27d6f327dbb 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -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. @@ -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