an atomic compare_exchange.

This commit is contained in:
Herbert Wolverson 2023-02-14 21:36:16 +00:00
parent dcb0ae8444
commit 6fe97e97b6

View File

@ -1,24 +1,30 @@
use lazy_static::*;
use lqos_bus::BusResponse; use lqos_bus::BusResponse;
use parking_lot::Mutex; use std::{process::Command, sync::atomic::AtomicBool};
use std::process::Command;
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
lazy_static! { static TEST_BUSY: AtomicBool = AtomicBool::new(false);
static ref TEST_BUSY: Mutex<bool> = Mutex::new(false);
}
pub fn lqos_daht_test() -> BusResponse { pub fn lqos_daht_test() -> BusResponse {
spawn_blocking(|| { spawn_blocking(|| {
if let Some(_lock) = TEST_BUSY.try_lock() { if TEST_BUSY.compare_exchange(
Command::new("/bin/ssh") false,
true,
std::sync::atomic::Ordering::Relaxed,
std::sync::atomic::Ordering::Relaxed,
) == Ok(true)
{
let result = Command::new("/bin/ssh")
.args([ .args([
"-t", "-t",
"lqtest@lqos.taht.net", "lqtest@lqos.taht.net",
"\"/home/lqtest/bin/v6vsv4.sh\"", "\"/home/lqtest/bin/v6vsv4.sh\"",
]) ])
.output() .output();
.unwrap(); if result.is_err() {
log::warn!("Unable to call dtaht test: {:?}", result);
}
TEST_BUSY.store(false, std::sync::atomic::Ordering::Relaxed);
} }
}); });
BusResponse::Ack BusResponse::Ack