mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2024-11-24 17:20:16 -06:00
an atomic compare_exchange.
This commit is contained in:
parent
dcb0ae8444
commit
6fe97e97b6
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user