From 947557cc399fc527059f1df197288d19c78cf6c3 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 1 Jul 2024 14:18:31 -0700 Subject: [PATCH] separate types for triggering and awaiting activation --- nexus/src/app/background/driver.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nexus/src/app/background/driver.rs b/nexus/src/app/background/driver.rs index 24aed22a02..7ea33b8554 100644 --- a/nexus/src/app/background/driver.rs +++ b/nexus/src/app/background/driver.rs @@ -139,7 +139,7 @@ impl Driver { name.clone(), )])); let task_exec = - TaskExec::new(period, imp, activator.clone(), opctx, status_tx); + TaskExec::new(period, imp, activator.0.clone(), opctx, status_tx); let tokio_task = tokio::task::spawn(task_exec.run(watchers)); // Create an object to track our side of the background task's state. @@ -256,7 +256,9 @@ impl Activator { pub fn activate(&self) { self.0.notify.notify_one(); } +} +impl ActivatorInner { async fn activated(&self) { debug_assert!( self.0.wired_up.load(Ordering::SeqCst), @@ -276,7 +278,7 @@ struct TaskExec { imp: Box, /// used to receive notifications from the Driver that someone has requested /// explicit activation - activator: Activator, + activation: Arc, /// passed through to the background task impl when activated opctx: OpContext, /// used to send current status back to the Driver @@ -289,11 +291,11 @@ impl TaskExec { fn new( period: Duration, imp: Box, - activator: Activator, + activation: Arc, opctx: OpContext, status_tx: watch::Sender, ) -> TaskExec { - TaskExec { period, imp, activator, opctx, status_tx, iteration: 0 } + TaskExec { period, imp, activation, opctx, status_tx, iteration: 0 } } /// Body of the tokio task that manages activation of this background task @@ -313,7 +315,7 @@ impl TaskExec { self.activate(ActivationReason::Timeout).await; }, - _ = self.activator.activated() => { + _ = self.activation.activated() => { self.activate(ActivationReason::Signaled).await; }