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

Commit

Permalink
hypervisor lifecycle alter
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Aug 26, 2016
1 parent 9ee993d commit 108e034
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
// Handle exit
wait_for_exit(panic_handler, http_server, ipc_server, dapps_server, signer_server);

// hypervisor should be shutdown first while everything still works and can be
// terminated gracefully
drop(hypervisor);

Ok(())
}

Expand Down
13 changes: 7 additions & 6 deletions parity/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn main() {
let sync = EthSync::new(service_config.sync, remote_client.service().clone(), service_config.net).unwrap();

let _ = boot::main_thread();
let stop = Arc::new(AtomicBool::new(false));
let service_stop = Arc::new(AtomicBool::new(false));

let hypervisor = boot::register(
&service_urls::with_base(&service_config.io_path, HYPERVISOR_IPC_URL),
Expand All @@ -58,30 +58,31 @@ pub fn main() {

boot::host_service(
&service_urls::with_base(&service_config.io_path, service_urls::SYNC),
stop.clone(),
service_stop.clone(),
sync.clone() as Arc<SyncProvider>
);
boot::host_service(
&service_urls::with_base(&service_config.io_path, service_urls::NETWORK_MANAGER),
stop.clone(),
service_stop.clone(),
sync.clone() as Arc<ManageNetwork>
);
boot::host_service(
&service_urls::with_base(&service_config.io_path, service_urls::SYNC_NOTIFY),
stop.clone(),
service_stop.clone(),
sync.clone() as Arc<ChainNotify>
);

let control_service = Arc::new(SyncControlService { stop: stop.clone() });
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);
worker.add_reqrep(
&service_urls::with_base(&service_config.io_path, service_urls::SYNC_CONTROL)
).unwrap();

while !stop.load(::std::sync::atomic::Ordering::Relaxed) {
while !control_service.stop.load(::std::sync::atomic::Ordering::Relaxed) {
worker.poll();
}
service_stop.store(true, ::std::sync::atomic::Ordering::Relaxed);

hypervisor.module_shutdown(SYNC_MODULE_ID);
trace!(target: "hypervisor", "Sync process terminated gracefully");
Expand Down

0 comments on commit 108e034

Please sign in to comment.