#[allow(unused_imports)]
use super::metadata::BlockMetadataPersist;
#[allow(unused_imports)]
use crate::types::DatabaseError;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
#[cfg(target_arch = "wasm32")]
thread_local! {
pub static GLOBAL_STORAGE: RefCell<HashMap<String, HashMap<u64, Vec<u8>>>> = RefCell::new(HashMap::new());
static GLOBAL_ALLOCATION_MAP: RefCell<HashMap<String, HashSet<u64>>> = RefCell::new(HashMap::new());
}
#[cfg(not(target_arch = "wasm32"))]
thread_local! {
static GLOBAL_STORAGE_TEST: RefCell<HashMap<String, HashMap<u64, Vec<u8>>>> = RefCell::new(HashMap::new());
static GLOBAL_ALLOCATION_MAP_TEST: RefCell<HashMap<String, HashSet<u64>>> = RefCell::new(HashMap::new());
}
#[cfg(target_arch = "wasm32")]
thread_local! {
static GLOBAL_METADATA: RefCell<HashMap<String, HashMap<u64, BlockMetadataPersist>>> = RefCell::new(HashMap::new());
}
#[cfg(target_arch = "wasm32")]
thread_local! {
pub static GLOBAL_COMMIT_MARKER: RefCell<HashMap<String, u64>> = RefCell::new(HashMap::new());
}
#[cfg(target_arch = "wasm32")]
pub fn with_global_storage<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, HashMap<u64, Vec<u8>>>>) -> R,
{
GLOBAL_STORAGE.with(f)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn with_global_storage<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, HashMap<u64, Vec<u8>>>>) -> R,
{
GLOBAL_STORAGE_TEST.with(f)
}
#[cfg(target_arch = "wasm32")]
pub fn with_global_metadata<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, HashMap<u64, BlockMetadataPersist>>>) -> R,
{
GLOBAL_METADATA.with(f)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn with_global_metadata<F, R>(f: F) -> R
where
F: FnOnce(&parking_lot::Mutex<HashMap<String, HashMap<u64, BlockMetadataPersist>>>) -> R,
{
use super::block_storage::GLOBAL_METADATA_TEST;
GLOBAL_METADATA_TEST.with(f)
}
#[cfg(target_arch = "wasm32")]
pub fn with_global_commit_marker<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, u64>>) -> R,
{
GLOBAL_COMMIT_MARKER.with(f)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn with_global_commit_marker<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, u64>>) -> R,
{
thread_local! {
static GLOBAL_COMMIT_MARKER_TEST: RefCell<HashMap<String, u64>> = RefCell::new(HashMap::new());
}
GLOBAL_COMMIT_MARKER_TEST.with(f)
}
#[cfg(target_arch = "wasm32")]
pub fn with_global_allocation_map<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, HashSet<u64>>>) -> R,
{
GLOBAL_ALLOCATION_MAP.with(f)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn with_global_allocation_map<F, R>(f: F) -> R
where
F: FnOnce(&RefCell<HashMap<String, HashSet<u64>>>) -> R,
{
GLOBAL_ALLOCATION_MAP_TEST.with(f)
}