2021-09-14 15:51:07 -07:00
|
|
|
use crate::accounts_index::IndexValue;
|
2021-09-12 15:14:59 -07:00
|
|
|
use crate::bucket_map_holder_stats::BucketMapHolderStats;
|
|
|
|
use crate::waitable_condvar::WaitableCondvar;
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
// will eventually hold the bucket map
|
|
|
|
#[derive(Debug, Default)]
|
2021-09-14 15:51:07 -07:00
|
|
|
pub struct BucketMapHolder<T: IndexValue> {
|
2021-09-12 15:14:59 -07:00
|
|
|
pub stats: BucketMapHolderStats,
|
2021-09-13 20:59:03 -07:00
|
|
|
_phantom: std::marker::PhantomData<T>,
|
2021-09-12 15:14:59 -07:00
|
|
|
}
|
|
|
|
|
2021-09-14 15:51:07 -07:00
|
|
|
impl<T: IndexValue> BucketMapHolder<T> {
|
2021-09-12 15:14:59 -07:00
|
|
|
pub fn new() -> Self {
|
2021-09-13 20:59:03 -07:00
|
|
|
Self::default()
|
2021-09-12 15:14:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// intended to execute in a bg thread
|
|
|
|
pub fn background(&self, exit: Arc<AtomicBool>, wait: Arc<WaitableCondvar>) {
|
|
|
|
loop {
|
|
|
|
wait.wait_timeout(Duration::from_millis(10000)); // account index stats every 10 s
|
|
|
|
if exit.load(Ordering::Relaxed) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
self.stats.report_stats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|