Synchronization tweaks for IPC services (#2028)
* using sequentally consistent checks * making shutdown method synchronous * redndant line
This commit is contained in:
parent
b4f3c4bd7a
commit
3439c06a1c
@ -42,7 +42,7 @@ pub struct ModuleState {
|
||||
|
||||
#[derive(Ipc)]
|
||||
pub trait ControlService {
|
||||
fn shutdown(&self);
|
||||
fn shutdown(&self) -> bool;
|
||||
}
|
||||
|
||||
#[derive(Ipc)]
|
||||
|
@ -42,7 +42,7 @@ pub fn host_service<T: ?Sized + Send + Sync + 'static>(addr: &str, stop_guard: A
|
||||
let mut worker = nanoipc::Worker::<T>::new(&service);
|
||||
worker.add_reqrep(&socket_url).unwrap();
|
||||
|
||||
while !stop_guard.load(Ordering::Relaxed) {
|
||||
while !stop_guard.load(Ordering::SeqCst) {
|
||||
worker.poll();
|
||||
}
|
||||
});
|
||||
|
@ -31,9 +31,10 @@ struct SyncControlService {
|
||||
}
|
||||
|
||||
impl ControlService for SyncControlService {
|
||||
fn shutdown(&self) {
|
||||
fn shutdown(&self) -> bool {
|
||||
trace!(target: "hypervisor", "Received shutdown from control service");
|
||||
self.stop.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
||||
self.stop.store(true, ::std::sync::atomic::Ordering::SeqCst);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,14 +76,15 @@ pub fn main() {
|
||||
let control_service = Arc::new(SyncControlService::default());
|
||||
let as_control = control_service.clone() as Arc<ControlService>;
|
||||
let mut worker = nanoipc::Worker::<ControlService>::new(&as_control);
|
||||
let thread_stop = control_service.stop.clone();
|
||||
worker.add_reqrep(
|
||||
&service_urls::with_base(&service_config.io_path, service_urls::SYNC_CONTROL)
|
||||
).unwrap();
|
||||
|
||||
while !control_service.stop.load(::std::sync::atomic::Ordering::Relaxed) {
|
||||
while !thread_stop.load(::std::sync::atomic::Ordering::SeqCst) {
|
||||
worker.poll();
|
||||
}
|
||||
service_stop.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
||||
service_stop.store(true, ::std::sync::atomic::Ordering::SeqCst);
|
||||
|
||||
hypervisor.module_shutdown(SYNC_MODULE_ID);
|
||||
trace!(target: "hypervisor", "Sync process terminated gracefully");
|
||||
|
Loading…
Reference in New Issue
Block a user