fix Supplied instant is later than self

This commit is contained in:
draganrakita 2021-01-14 15:55:52 +01:00 committed by rakita
parent ea25ffd79d
commit 1d07c4c06b
8 changed files with 26 additions and 14 deletions

View File

@ -224,7 +224,14 @@ impl<T: InformantData> Informant<T> {
pub fn tick(&self) {
let now = Instant::now();
let elapsed = now.duration_since(*self.last_tick.read());
let elapsed;
{
let last_tick = self.last_tick.read();
if now < *last_tick + Duration::from_millis(1500) {
return;
}
elapsed = now - *last_tick;
}
let (client_report, full_report) = {
let last_report = self.last_report.lock();

View File

@ -56,7 +56,7 @@ impl ClientService {
_ipc_path: &Path,
miner: Arc<Miner>,
) -> Result<ClientService, Error> {
let io_service = IoService::<ClientIoMessage>::start()?;
let io_service = IoService::<ClientIoMessage>::start("Client")?;
info!(
"Configured for {} using {} engine",

View File

@ -764,7 +764,7 @@ impl AuthorityRound {
.start_step
.unwrap_or_else(|| (unix_now().as_secs() / (our_params.step_duration as u64)));
let engine = Arc::new(AuthorityRound {
transition_service: IoService::<()>::start()?,
transition_service: IoService::<()>::start("AuRa")?,
step: Arc::new(PermissionedStep {
inner: Step {
inner: AtomicUsize::new(initial_step as usize),

View File

@ -1001,7 +1001,7 @@ mod tests {
fn sends_async_messages() {
let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()];
let client = generate_dummy_client_with_spec_and_data(Spec::new_null, 400, 5, &gas_prices);
let service = IoService::<ClientIoMessage>::start().unwrap();
let service = IoService::<ClientIoMessage>::start("Test").unwrap();
let spec = Spec::new_test();
let tempdir = TempDir::new("").unwrap();

View File

@ -60,7 +60,7 @@ impl NetworkService {
let host_handler = Arc::new(HostHandler {
public_url: RwLock::new(None),
});
let io_service = IoService::<NetworkIoMessage>::start()?;
let io_service = IoService::<NetworkIoMessage>::start("devp2p")?;
Ok(NetworkService {
io_service,

View File

@ -46,7 +46,7 @@
//! }
//!
//! fn main () {
//! let mut service = IoService::<MyMessage>::start().expect("Error creating network service");
//! let mut service = IoService::<MyMessage>::start("name").expect("Error creating network service");
//! service.register_handler(Arc::new(MyHandler)).unwrap();
//!
//! // Wait for quit condition
@ -239,7 +239,8 @@ mod tests {
let handler = Arc::new(MyHandler(atomic::AtomicBool::new(false)));
let service = IoService::<MyMessage>::start().expect("Error creating network service");
let service =
IoService::<MyMessage>::start("Test").expect("Error creating network service");
service.register_handler(handler.clone()).unwrap();
service.send_message(MyMessage { data: 5 }).unwrap();
@ -271,7 +272,8 @@ mod tests {
let handler = Arc::new(MyHandler(atomic::AtomicBool::new(false)));
let service = IoService::<MyMessage>::start().expect("Error creating network service");
let service =
IoService::<MyMessage>::start("Test").expect("Error creating network service");
service.register_handler(handler.clone()).unwrap();
thread::sleep(Duration::from_secs(2));
@ -300,7 +302,8 @@ mod tests {
let handler = Arc::new(MyHandler(atomic::AtomicUsize::new(0)));
let service = IoService::<MyMessage>::start().expect("Error creating network service");
let service =
IoService::<MyMessage>::start("Test").expect("Error creating network service");
service.register_handler(handler.clone()).unwrap();
thread::sleep(Duration::from_secs(2));

View File

@ -210,6 +210,7 @@ where
{
/// Creates a new instance and registers it with the event loop.
pub fn start(
symbolic_name: &str,
event_loop: &mut EventLoop<IoManager<Message>>,
handlers: Arc<RwLock<Slab<Arc<dyn IoHandler<Message>>>>>,
) -> Result<(), IoError> {
@ -220,7 +221,7 @@ where
let workers = (0..num_workers)
.map(|i| {
Worker::new(
i,
&format!("{}{}", symbolic_name, i),
stealer.clone(),
IoChannel::new(event_loop.channel(), Arc::downgrade(&handlers)),
work_ready.clone(),
@ -534,7 +535,7 @@ where
Message: Send + Sync + 'static,
{
/// Starts IO event loop
pub fn start() -> Result<IoService<Message>, IoError> {
pub fn start(symbolic_name: &'static str) -> Result<IoService<Message>, IoError> {
let mut config = EventLoopBuilder::new();
config.messages_per_tick(1024);
let mut event_loop = config.build().expect("Error creating event loop");
@ -542,7 +543,8 @@ where
let handlers = Arc::new(RwLock::new(Slab::with_capacity(MAX_HANDLERS)));
let h = handlers.clone();
let thread = thread::spawn(move || {
IoManager::<Message>::start(&mut event_loop, h).expect("Error starting IO service");
IoManager::<Message>::start(symbolic_name, &mut event_loop, h)
.expect("Error starting IO service");
});
Ok(IoService {
thread: Some(thread),

View File

@ -59,7 +59,7 @@ pub struct Worker {
impl Worker {
/// Creates a new worker instance.
pub fn new<Message>(
index: usize,
name: &str,
stealer: deque::Stealer<Work<Message>>,
channel: IoChannel<Message>,
wait: Arc<Condvar>,
@ -78,7 +78,7 @@ impl Worker {
worker.thread = Some(
thread::Builder::new()
.stack_size(STACK_SIZE)
.name(format!("IO Worker #{}", index))
.name(format!("Worker {}", name))
.spawn(move || {
LOCAL_STACK_SIZE.with(|val| val.set(STACK_SIZE));
let ini = (stealer, channel.clone(), wait, wait_mutex.clone(), deleting);