fix(agent): reserve shared runtime atomically
This commit is contained in:
2 files changed
+166
-14
No files matched your search
@@ -203,11 +203,12 @@ impl AgentRuntimeClient {
|
||||
self.active_sessions.fetch_add(1, Ordering::AcqRel);
|
||||
}
|
||||
|
||||
pub fn decrement_session_count(runtime: &Arc<Self>) {
|
||||
pub fn decrement_session_count(runtime: &Arc<Self>) -> u64 {
|
||||
let previous = runtime
|
||||
.active_sessions
|
||||
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |value| Some(value.saturating_sub(1)))
|
||||
.unwrap_or_default();
|
||||
let remaining = previous.saturating_sub(1);
|
||||
if previous <= 1 {
|
||||
let runtime = runtime.clone();
|
||||
tokio::spawn(async move {
|
||||
@@ -217,6 +218,7 @@ impl AgentRuntimeClient {
|
||||
}
|
||||
});
|
||||
}
|
||||
remaining
|
||||
}
|
||||
|
||||
pub fn kill(&self) {
|
||||
|
||||
Reference in new issue
Block a user