diff --git a/sdk/program/src/slot_hashes.rs b/sdk/program/src/slot_hashes.rs index 56d891b7aa..82d824f558 100644 --- a/sdk/program/src/slot_hashes.rs +++ b/sdk/program/src/slot_hashes.rs @@ -5,23 +5,25 @@ pub use crate::clock::Slot; use { 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 // This is to allow tests with custom slot hash expiry to avoid having to generate // 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 { - unsafe { NUM_ENTRIES } + NUM_ENTRIES.load(Ordering::Relaxed) } -pub fn set_entries_for_tests_only(_entries: usize) { - unsafe { - NUM_ENTRIES = _entries; - } +pub fn set_entries_for_tests_only(entries: usize) { + NUM_ENTRIES.store(entries, Ordering::Relaxed); } pub type SlotHash = (Slot, Hash);