Skip to main content

xmtp_mls_core/
task_channels.rs

1use std::sync::Arc;
2
3#[derive(Clone)]
4pub struct TaskWorkerChannels {
5    /// Serializes notification requests across inline calls and task turns.
6    pub notification_request: Arc<tokio::sync::Mutex<()>>,
7    notification_revision: Arc<std::sync::atomic::AtomicUsize>,
8}
9
10impl Default for TaskWorkerChannels {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl TaskWorkerChannels {
17    pub fn new() -> Self {
18        Self {
19            notification_request: Default::default(),
20            notification_revision: Default::default(),
21        }
22    }
23
24    /// Invalidate a prepared notification batch after a local change.
25    pub fn mark_notification_changed(&self) {
26        use std::sync::atomic::Ordering;
27        self.notification_revision.fetch_add(1, Ordering::AcqRel);
28    }
29
30    /// The count of local notification changes, for checking that a prepared
31    /// batch is still current.
32    pub fn notification_revision(&self) -> usize {
33        self.notification_revision
34            .load(std::sync::atomic::Ordering::Acquire)
35    }
36}