Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Synchronization tweaks for IPC services #2028

Merged
merged 3 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ipc/hypervisor/src/service.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct ModuleState {

#[derive(Ipc)]
pub trait ControlService {
fn shutdown(&self);
fn shutdown(&self) -> bool;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a return type forces invocation to be synchronous
Until the exact issue will be found

}

#[derive(Ipc)]
Expand Down
3 changes: 2 additions & 1 deletion parity/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand All @@ -52,6 +52,7 @@ pub fn payload<B: ipc::BinaryConvertable>() -> Result<B, BootError> {
use std::io;
use std::io::Read;


let mut buffer = Vec::new();
try!(
io::stdin().read_to_end(&mut buffer)
Expand Down
10 changes: 6 additions & 4 deletions parity/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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");
Expand Down