blob: 2910616c678876ea09b938cab85d5b0f183391e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
//! The writers this node writes or wrote under in its current document.
use std::sync::Mutex;
use super::ActorId;
use crate::locks::MutexExt;
/// The actors this node writes or wrote with in the current document: this run's, and
/// those of earlier runs it knows of (`--document-file`). Its own writes, for a rejoin,
/// for signing and for dropping what it took. A switch or rejoin starts the list over
/// with the new document's actor, so it only grows with restarts within one epoch.
#[derive(Debug, Default)]
pub(crate) struct OwnWriters(Mutex<Vec<ActorId>>);
impl OwnWriters {
/// This node writes with `actor` from now on (or did, in an earlier run).
pub(crate) fn add(&self, actor: ActorId) {
let mut own = self.0.lock_or_recover();
if !own.contains(&actor) {
own.push(actor);
}
}
/// The current document is a new one, written with `actor` only (a switch or rejoin
/// is done).
pub(crate) fn reset(&self, actor: ActorId) {
*self.0.lock_or_recover() = vec![actor];
}
pub(crate) fn all(&self) -> Vec<ActorId> {
self.0.lock_or_recover().clone()
}
}
|