зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638927
- Replace `lazy_static` with `once_cell` in XULStore. r=froydnj
TSan returns false positives for `lazy_static`. While we could blocklist it, `once_cell` has equivalent functionality, but with a more modern API, so let's use it instead. Depends on D75864 Differential Revision: https://phabricator.services.mozilla.com/D76342
This commit is contained in:
Родитель
f2aad2aa4c
Коммит
1e4bad34ca
|
@ -5790,13 +5790,13 @@ dependencies = [
|
|||
"crossbeam-utils 0.6.5",
|
||||
"cstr",
|
||||
"failure",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"lmdb-rkv",
|
||||
"log",
|
||||
"moz_task",
|
||||
"nserror",
|
||||
"nsstring",
|
||||
"once_cell",
|
||||
"rkv 0.10.4",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
|
|
|
@ -7,13 +7,13 @@ license = "MPL-2.0"
|
|||
[dependencies]
|
||||
crossbeam-utils = "0.6.3"
|
||||
cstr = "0.1"
|
||||
lazy_static = "1.0"
|
||||
libc = "0.2"
|
||||
lmdb-rkv = "0.14"
|
||||
log = "0.4"
|
||||
moz_task = { path = "../../../xpcom/rust/moz_task" }
|
||||
nsstring = { path = "../../../xpcom/rust/nsstring" }
|
||||
nserror = { path = "../../../xpcom/rust/nserror" }
|
||||
once_cell = "1"
|
||||
rkv = "0.10.2"
|
||||
serde_json = "1"
|
||||
tempfile = "3"
|
||||
|
|
|
@ -7,8 +7,6 @@ extern crate crossbeam_utils;
|
|||
extern crate cstr;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate libc;
|
||||
extern crate lmdb;
|
||||
#[macro_use]
|
||||
|
@ -16,6 +14,7 @@ extern crate log;
|
|||
extern crate moz_task;
|
||||
extern crate nserror;
|
||||
extern crate nsstring;
|
||||
extern crate once_cell;
|
||||
extern crate rkv;
|
||||
extern crate serde_json;
|
||||
extern crate tempfile;
|
||||
|
|
|
@ -22,29 +22,29 @@ use crossbeam_utils::atomic::AtomicCell;
|
|||
use lmdb::Error as LmdbError;
|
||||
use moz_task::{dispatch_background_task_with_options, DispatchOptions, Task, TaskRunnable};
|
||||
use nserror::nsresult;
|
||||
use once_cell::sync::Lazy;
|
||||
use rkv::{StoreError as RkvStoreError, Value};
|
||||
use std::{collections::HashMap, sync::Mutex, thread::sleep, time::Duration};
|
||||
use xpcom::RefPtr;
|
||||
|
||||
lazy_static! {
|
||||
/// A map of key/value pairs to persist. Values are Options so we can
|
||||
/// use the same structure for both puts and deletes, with a `None` value
|
||||
/// identifying a key that should be deleted from the database.
|
||||
///
|
||||
/// This is a map rather than a sequence in order to merge consecutive
|
||||
/// changes to the same key, i.e. when a consumer sets *foo* to `bar`
|
||||
/// and then sets it again to `baz` before we persist the first change.
|
||||
///
|
||||
/// In that case, there's no point in setting *foo* to `bar` before we set
|
||||
/// it to `baz`, and the map ensures we only ever persist the latest value
|
||||
/// for any given key.
|
||||
static ref CHANGES: Mutex<Option<HashMap<String, Option<String>>>> = { Mutex::new(None) };
|
||||
/// A map of key/value pairs to persist. Values are Options so we can
|
||||
/// use the same structure for both puts and deletes, with a `None` value
|
||||
/// identifying a key that should be deleted from the database.
|
||||
///
|
||||
/// This is a map rather than a sequence in order to merge consecutive
|
||||
/// changes to the same key, i.e. when a consumer sets *foo* to `bar`
|
||||
/// and then sets it again to `baz` before we persist the first change.
|
||||
///
|
||||
/// In that case, there's no point in setting *foo* to `bar` before we set
|
||||
/// it to `baz`, and the map ensures we only ever persist the latest value
|
||||
/// for any given key.
|
||||
static CHANGES: Lazy<Mutex<Option<HashMap<String, Option<String>>>>> =
|
||||
Lazy::new(|| Mutex::new(None));
|
||||
|
||||
/// A Mutex that prevents two PersistTasks from running at the same time,
|
||||
/// since each task opens the database, and we need to ensure there is only
|
||||
/// one open database handle for the database at any given time.
|
||||
static ref PERSIST: Mutex<()> = { Mutex::new(()) };
|
||||
}
|
||||
/// A Mutex that prevents two PersistTasks from running at the same time,
|
||||
/// since each task opens the database, and we need to ensure there is only
|
||||
/// one open database handle for the database at any given time.
|
||||
static PERSIST: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
||||
|
||||
/// Synchronously persists changes recorded in memory to disk. Typically
|
||||
/// called from a background thread, however this can be called from the main
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
|||
use lmdb::Error as LmdbError;
|
||||
use moz_task::is_main_thread;
|
||||
use nsstring::nsString;
|
||||
use once_cell::sync::Lazy;
|
||||
use rkv::{migrate::Migrator, Rkv, SingleStore, StoreError, StoreOptions, Value};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
|
@ -34,14 +35,13 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PROFILE_DIR: Mutex<Option<PathBuf>> = {
|
||||
observe_profile_change();
|
||||
Mutex::new(get_profile_dir().ok())
|
||||
};
|
||||
pub(crate) static ref DATA_CACHE: Mutex<Option<XULStoreCache>> =
|
||||
{ Mutex::new(cache_data().ok()) };
|
||||
}
|
||||
static PROFILE_DIR: Lazy<Mutex<Option<PathBuf>>> = Lazy::new(|| {
|
||||
observe_profile_change();
|
||||
Mutex::new(get_profile_dir().ok())
|
||||
});
|
||||
|
||||
pub(crate) static DATA_CACHE: Lazy<Mutex<Option<XULStoreCache>>> =
|
||||
Lazy::new(|| Mutex::new(cache_data().ok()));
|
||||
|
||||
pub(crate) fn get_database() -> XULStoreResult<Database> {
|
||||
let xulstore_dir = get_xulstore_dir()?;
|
||||
|
|
Загрузка…
Ссылка в новой задаче