pass restart_idle semaphore
This commit is contained in:
parent
69e7d88dbc
commit
90312e2fb7
@ -804,12 +804,14 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
|
||||
}
|
||||
}
|
||||
let cfg = Rc::new(cfg);
|
||||
mgmt::start(cfg.clone());
|
||||
let restart_idle = Rc::new(Semaphore::new(0, 1));
|
||||
mgmt::start(cfg.clone(), restart_idle.clone());
|
||||
|
||||
task::spawn(async move {
|
||||
let terminate = Rc::new(Semaphore::new(0, 1));
|
||||
let running = Rc::new(Mutex::new(false));
|
||||
let repeat_lock = Rc::new(Mutex::new(false));
|
||||
let restart_idle = restart_idle.clone();
|
||||
let cfg = cfg.clone();
|
||||
let control = control.clone();
|
||||
let up_destinations = up_destinations.clone();
|
||||
@ -867,6 +869,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
|
||||
let terminate = terminate.clone();
|
||||
let running = running.clone();
|
||||
let repeat_lock = repeat_lock.clone();
|
||||
let restart_idle = restart_idle.clone();
|
||||
|
||||
let _rep_lock = repeat_lock.async_lock().await;
|
||||
drop(_rep_lock);
|
||||
@ -881,6 +884,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
|
||||
}
|
||||
}).fuse() => (),
|
||||
_ = terminate.async_wait().fuse() => (),
|
||||
_ = restart_idle.async_wait().fuse() => ()
|
||||
}
|
||||
info!("supposed to drop idle kernel");
|
||||
drop(_lock);
|
||||
@ -933,7 +937,8 @@ pub fn soft_panic_main(timer: GlobalTimer, cfg: Config) -> ! {
|
||||
|
||||
Sockets::init(32);
|
||||
|
||||
mgmt::start(Rc::new(cfg));
|
||||
let dummy_restart = Rc::new(Semaphore::new(0, 1));
|
||||
mgmt::start(Rc::new(cfg), dummy_restart);
|
||||
|
||||
// getting eth settings disables the LED as it resets GPIO
|
||||
// need to re-enable it here
|
||||
|
@ -6,6 +6,7 @@ use libasync::{smoltcp::TcpStream, task};
|
||||
use libboard_artiq::logger::{BufferLogger, LogBufferRef};
|
||||
use libboard_zynq::{slcr, smoltcp};
|
||||
use libconfig::Config;
|
||||
use libcortex_a9::semaphore::Semaphore;
|
||||
use log::{self, debug, error, info, warn, LevelFilter};
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
@ -111,7 +112,7 @@ async fn read_key(stream: &mut TcpStream) -> Result<String> {
|
||||
Ok(String::from_utf8(buffer).unwrap())
|
||||
}
|
||||
|
||||
async fn handle_connection(stream: &mut TcpStream, pull_id: Rc<RefCell<u32>>, cfg: Rc<Config>) -> Result<()> {
|
||||
async fn handle_connection(stream: &mut TcpStream, pull_id: Rc<RefCell<u32>>, cfg: Rc<Config>, restart_idle: Rc<Semaphore>) -> Result<()> {
|
||||
if !expect(&stream, b"ARTIQ management\n").await? {
|
||||
return Err(Error::UnexpectedPattern);
|
||||
}
|
||||
@ -201,6 +202,9 @@ async fn handle_connection(stream: &mut TcpStream, pull_id: Rc<RefCell<u32>>, cf
|
||||
if value.is_ok() {
|
||||
debug!("write success");
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
if key == "idle_kernel" {
|
||||
restart_idle.signal();
|
||||
}
|
||||
} else {
|
||||
// this is an error because we do not expect write to fail
|
||||
error!("failed to write: {:?}", value);
|
||||
@ -229,16 +233,17 @@ async fn handle_connection(stream: &mut TcpStream, pull_id: Rc<RefCell<u32>>, cf
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(cfg: Rc<Config>) {
|
||||
pub fn start(cfg: Rc<Config>, restart_idle: Rc<Semaphore>) {
|
||||
task::spawn(async move {
|
||||
let pull_id = Rc::new(RefCell::new(0u32));
|
||||
loop {
|
||||
let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap();
|
||||
let pull_id = pull_id.clone();
|
||||
let restart_idle = restart_idle.clone();
|
||||
let cfg = cfg.clone();
|
||||
task::spawn(async move {
|
||||
info!("received connection");
|
||||
let _ = handle_connection(&mut stream, pull_id, cfg)
|
||||
let _ = handle_connection(&mut stream, pull_id, cfg, restart_idle)
|
||||
.await
|
||||
.map_err(|e| warn!("connection terminated: {:?}", e));
|
||||
let _ = stream.flush().await;
|
||||
|
Loading…
Reference in New Issue
Block a user