Make stop const

This commit is contained in:
arkpar 2016-12-09 13:25:02 +01:00
parent 22a63f6fd3
commit 364dd9dda4
1 changed files with 4 additions and 4 deletions

View File

@ -394,7 +394,7 @@ impl<Message> IoChannel<Message> where Message: Send + Clone + Sync + 'static {
/// 'Message' is a notification message type /// 'Message' is a notification message type
pub struct IoService<Message> where Message: Send + Sync + Clone + 'static { pub struct IoService<Message> where Message: Send + Sync + Clone + 'static {
panic_handler: Arc<PanicHandler>, panic_handler: Arc<PanicHandler>,
thread: Option<JoinHandle<()>>, thread: Mutex<Option<JoinHandle<()>>>,
host_channel: Mutex<Sender<IoMessage<Message>>>, host_channel: Mutex<Sender<IoMessage<Message>>>,
handlers: Arc<RwLock<Slab<Arc<IoHandler<Message>>, HandlerId>>>, handlers: Arc<RwLock<Slab<Arc<IoHandler<Message>>, HandlerId>>>,
} }
@ -424,19 +424,19 @@ impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
}); });
Ok(IoService { Ok(IoService {
panic_handler: panic_handler, panic_handler: panic_handler,
thread: Some(thread), thread: Mutex::new(Some(thread)),
host_channel: Mutex::new(channel), host_channel: Mutex::new(channel),
handlers: handlers, handlers: handlers,
}) })
} }
pub fn stop(&mut self) { pub fn stop(&self) {
trace!(target: "shutdown", "[IoService] Closing..."); trace!(target: "shutdown", "[IoService] Closing...");
// Clear handlers so that shared pointers are not stuck on stack // Clear handlers so that shared pointers are not stuck on stack
// in Channel::send_sync // in Channel::send_sync
self.handlers.write().clear(); self.handlers.write().clear();
self.host_channel.lock().send(IoMessage::Shutdown).unwrap_or_else(|e| warn!("Error on IO service shutdown: {:?}", e)); self.host_channel.lock().send(IoMessage::Shutdown).unwrap_or_else(|e| warn!("Error on IO service shutdown: {:?}", e));
if let Some(thread) = self.thread.take() { if let Some(thread) = self.thread.lock().take() {
thread.join().unwrap_or_else(|e| { thread.join().unwrap_or_else(|e| {
debug!(target: "shutdown", "Error joining IO service event loop thread: {:?}", e); debug!(target: "shutdown", "Error joining IO service event loop thread: {:?}", e);
}); });