Use atomics instead of mutable statics in slot_hashes (#24091)
This commit is contained in:
@ -5,23 +5,25 @@
|
|||||||
pub use crate::clock::Slot;
|
pub use crate::clock::Slot;
|
||||||
use {
|
use {
|
||||||
crate::hash::Hash,
|
crate::hash::Hash,
|
||||||
std::{iter::FromIterator, ops::Deref},
|
std::{
|
||||||
|
iter::FromIterator,
|
||||||
|
ops::Deref,
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const MAX_ENTRIES: usize = 512; // about 2.5 minutes to get your vote in
|
pub const MAX_ENTRIES: usize = 512; // about 2.5 minutes to get your vote in
|
||||||
|
|
||||||
// This is to allow tests with custom slot hash expiry to avoid having to generate
|
// This is to allow tests with custom slot hash expiry to avoid having to generate
|
||||||
// 512 blocks for such tests.
|
// 512 blocks for such tests.
|
||||||
static mut NUM_ENTRIES: usize = MAX_ENTRIES;
|
static NUM_ENTRIES: AtomicUsize = AtomicUsize::new(MAX_ENTRIES);
|
||||||
|
|
||||||
pub fn get_entries() -> usize {
|
pub fn get_entries() -> usize {
|
||||||
unsafe { NUM_ENTRIES }
|
NUM_ENTRIES.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_entries_for_tests_only(_entries: usize) {
|
pub fn set_entries_for_tests_only(entries: usize) {
|
||||||
unsafe {
|
NUM_ENTRIES.store(entries, Ordering::Relaxed);
|
||||||
NUM_ENTRIES = _entries;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SlotHash = (Slot, Hash);
|
pub type SlotHash = (Slot, Hash);
|
||||||
|
Reference in New Issue
Block a user