From 3439c06a1c2ce58d2336c39065e4b3780b78ec5f Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 1 Sep 2016 14:04:19 +0400 Subject: [PATCH] Synchronization tweaks for IPC services (#2028) * using sequentally consistent checks * making shutdown method synchronous * redndant line --- ipc/hypervisor/src/service.rs.in | 2 +- parity/boot.rs | 2 +- parity/sync.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ipc/hypervisor/src/service.rs.in b/ipc/hypervisor/src/service.rs.in index 69585ee6c..938cea345 100644 --- a/ipc/hypervisor/src/service.rs.in +++ b/ipc/hypervisor/src/service.rs.in @@ -42,7 +42,7 @@ pub struct ModuleState { #[derive(Ipc)] pub trait ControlService { - fn shutdown(&self); + fn shutdown(&self) -> bool; } #[derive(Ipc)] diff --git a/parity/boot.rs b/parity/boot.rs index 1614317b8..aa0e4b82b 100644 --- a/parity/boot.rs +++ b/parity/boot.rs @@ -42,7 +42,7 @@ pub fn host_service(addr: &str, stop_guard: A let mut worker = nanoipc::Worker::::new(&service); worker.add_reqrep(&socket_url).unwrap(); - while !stop_guard.load(Ordering::Relaxed) { + while !stop_guard.load(Ordering::SeqCst) { worker.poll(); } }); diff --git a/parity/sync.rs b/parity/sync.rs index 95c9924c6..27e9d5a6a 100644 --- a/parity/sync.rs +++ b/parity/sync.rs @@ -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; let mut worker = nanoipc::Worker::::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");