Counting peers on drop
This commit is contained in:
parent
67afdb0aa5
commit
0fdf6ad429
2 changed files with 14 additions and 0 deletions
|
|
@ -91,6 +91,12 @@ impl PeerStateNoMut {
|
|||
self.set(Default::default(), counters)
|
||||
}
|
||||
|
||||
pub fn destroy(self, counters: &[&AggregatePeerStatsAtomic]) {
|
||||
for counter in counters {
|
||||
counter.dec(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, new: PeerState, counters: &[&AggregatePeerStatsAtomic]) -> PeerState {
|
||||
for counter in counters {
|
||||
counter.incdec(&self.0, &new);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ pub(crate) struct PeerStates {
|
|||
pub states: DashMap<PeerHandle, Peer>,
|
||||
}
|
||||
|
||||
impl Drop for PeerStates {
|
||||
fn drop(&mut self) {
|
||||
for (_, p) in std::mem::take(&mut self.states).into_iter() {
|
||||
p.state.destroy(&[&self.session_stats.peers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PeerStates {
|
||||
pub fn stats(&self) -> AggregatePeerStats {
|
||||
AggregatePeerStats::from(&self.stats)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue