From 6c9bb58ec85ae1ff3aa646e801b5ae5687a0ca4e Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Fri, 30 Oct 2015 15:23:04 -0700 Subject: [PATCH] integrate upstream changes from Wonder --- src/bldr/util/signals.rs | 11 +++++------ vendor/wonder/src/actor.rs | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/bldr/util/signals.rs b/src/bldr/util/signals.rs index 42402bba28..e04aad1beb 100644 --- a/src/bldr/util/signals.rs +++ b/src/bldr/util/signals.rs @@ -23,10 +23,9 @@ use std::sync::{Once, ONCE_INIT}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering, ATOMIC_USIZE_INIT, ATOMIC_BOOL_INIT}; -use std::sync::mpsc::Sender; use wonder::actor; -use wonder::actor::{HandleResult, InitResult, StopReason}; +use wonder::actor::{ActorSender, HandleResult, InitResult, StopReason}; use error::{BldrResult, BldrError}; @@ -91,7 +90,7 @@ impl actor::GenServer for SignalNotifier { type S = (); type E = BldrError; - fn init(&self, _tx: &Sender>, _: &mut Self::S) -> InitResult { + fn init(&self, _tx: &ActorSender, _: &mut Self::S) -> InitResult { unsafe { INIT.call_once(|| { self::set_signal_handlers(); @@ -105,14 +104,14 @@ impl actor::GenServer for SignalNotifier { Ok(Some(TIMEOUT_MS)) } - fn handle_call(&self, message: Self::T, _: &Sender>, _: &Sender>, _: &mut Self::S) -> HandleResult { + fn handle_call(&self, message: Self::T, _: &ActorSender, _: &ActorSender, _: &mut Self::S) -> HandleResult { match message { Message::Stop => HandleResult::Stop(StopReason::Normal, None), msg => HandleResult::Stop(StopReason::Fatal(format!("unexpected call message: {:?}", msg)), None), } } - fn handle_timeout(&self, tx: &Sender>, _: &mut Self::S) -> HandleResult { + fn handle_timeout(&self, tx: &ActorSender, _: &ActorSender, _: &mut Self::S) -> HandleResult { unsafe { if CAUGHT.load(Ordering::SeqCst) { match SIGNAL.load(Ordering::SeqCst) { @@ -133,7 +132,7 @@ impl actor::GenServer for SignalNotifier { } } -fn send_signal(tx: &Sender>, signal: Signal) { +fn send_signal(tx: &ActorSender, signal: Signal) { actor::cast(tx, Message::Signal(signal)).unwrap(); } diff --git a/vendor/wonder/src/actor.rs b/vendor/wonder/src/actor.rs index 08015fd80c..a327378f94 100644 --- a/vendor/wonder/src/actor.rs +++ b/vendor/wonder/src/actor.rs @@ -99,7 +99,7 @@ impl Builder { loop { if let Some(go_time) = timeout { if go_time >= SteadyTime::now() { - match self.spec.handle_timeout(&itx, &mut state) { + match self.spec.handle_timeout(&otx, &itx, &mut state) { HandleResult::Stop(reason, None) => return shutdown(reason, None, &otx), HandleResult::NoReply(Some(0)) => { set_timeout(0, &mut timeout); @@ -132,7 +132,7 @@ impl Builder { } }, Ok(Message::Cast(msg)) => { - match self.spec.handle_cast(msg, &itx, &mut state) { + match self.spec.handle_cast(msg, &otx, &itx, &mut state) { HandleResult::Stop(reason, reply) => return shutdown(reason, reply, &otx), HandleResult::NoReply(new_timeout) => { if let Some(ms) = new_timeout { @@ -146,6 +146,14 @@ impl Builder { Err(mpsc::TryRecvError::Disconnected) => { break; }, Err(mpsc::TryRecvError::Empty) => { }, } + // This is absolutely the wrong solution. I need to park the thread or call + // recv instead of try_recv and schedule the timeout mechanism another way. + // This is a quick and dirty workaround that should be short lived while the API + // stabilizes and is leveraged in our other applications. + // + // I'm so sorry for doing this. + // - Jamie + thread::sleep_ms(30) } Ok(()) }).unwrap(); @@ -209,13 +217,15 @@ pub trait GenServer : Send + 'static { fn init(&self, _tx: &ActorSender, state: &mut Self::S) -> InitResult; - fn handle_call(&self, _message: Self::T, _tx: &ActorSender, _caller: &ActorSender, _state: &mut Self::S) -> HandleResult { - panic!("handle_call callback not implemented"); + fn handle_call(&self, message: Self::T, _tx: &ActorSender, _me: &ActorSender, _state: &mut Self::S) -> HandleResult { + panic!("handle_call callback not implemented; received: {:?}", message); } - fn handle_cast(&self, _message: Self::T, _tx: &ActorSender, _state: &mut Self::S) -> HandleResult { - panic!("handle_cast callback not implemented"); + + fn handle_cast(&self, message: Self::T, _tx: &ActorSender, _me: &ActorSender, _state: &mut Self::S) -> HandleResult { + panic!("handle_cast callback not implemented; received: {:?}", message); } - fn handle_timeout(&self, _tx: &ActorSender, _state: &mut Self::S) -> HandleResult { + + fn handle_timeout(&self, _tx: &ActorSender, _me: &ActorSender, _state: &mut Self::S) -> HandleResult { HandleResult::NoReply(None) } } @@ -294,7 +304,7 @@ mod tests { } } - fn handle_cast(&self, msg: Self::T, _: &ActorSender, state: &mut Self::S) -> HandleResult { + fn handle_cast(&self, msg: Self::T, _: &ActorSender, _: &ActorSender, state: &mut Self::S) -> HandleResult { match msg { MyMessage::SetState(value) => { state.initialized = value;