replace synchronization primitives with those from parking_lot (#1593)

* parking_lot in cargo.toml

* replace all lock invocations with parking_lot ones

* use parking_lot synchronization primitives
This commit is contained in:
Robert Habermeier
2016-07-13 19:59:59 +02:00
committed by Gav Wood
parent 4226c0f631
commit 36d3d0d7d7
50 changed files with 547 additions and 550 deletions

View File

@@ -19,10 +19,9 @@ use self::ansi_term::Colour::{White, Yellow, Green, Cyan, Blue, Purple};
use self::ansi_term::Style;
use std::time::{Instant, Duration};
use std::sync::RwLock;
use std::ops::{Deref, DerefMut};
use ethsync::SyncStatus;
use util::{Uint, RwLockable, NetworkConfiguration};
use util::{Uint, RwLock, NetworkConfiguration};
use ethcore::client::*;
use number_prefix::{binary_prefix, Standalone, Prefixed};
@@ -75,20 +74,21 @@ impl Informant {
}
}
#[cfg_attr(feature="dev", allow(match_bool))]
pub fn tick(&self, client: &Client, maybe_status: Option<(SyncStatus, NetworkConfiguration)>) {
let elapsed = self.last_tick.unwrapped_read().elapsed();
let elapsed = self.last_tick.read().elapsed();
if elapsed < Duration::from_secs(5) {
return;
}
*self.last_tick.unwrapped_write() = Instant::now();
*self.last_tick.write() = Instant::now();
let chain_info = client.chain_info();
let queue_info = client.queue_info();
let cache_info = client.blockchain_cache_info();
let mut write_report = self.report.unwrapped_write();
let mut write_report = self.report.write();
let report = client.report();
let paint = |c: Style, t: String| match self.with_color {
@@ -97,8 +97,8 @@ impl Informant {
};
if let (_, _, &Some(ref last_report)) = (
self.chain_info.unwrapped_read().deref(),
self.cache_info.unwrapped_read().deref(),
self.chain_info.read().deref(),
self.cache_info.read().deref(),
write_report.deref()
) {
println!("{} {} {} blk/s {} tx/s {} Mgas/s {}{}+{} Qed {} db {} chain {} queue{}",
@@ -133,8 +133,8 @@ impl Informant {
);
}
*self.chain_info.unwrapped_write().deref_mut() = Some(chain_info);
*self.cache_info.unwrapped_write().deref_mut() = Some(cache_info);
*self.chain_info.write().deref_mut() = Some(chain_info);
*self.cache_info.write().deref_mut() = Some(cache_info);
*write_report.deref_mut() = Some(report);
}
}

View File

@@ -74,7 +74,7 @@ mod url;
use std::io::{Write, Read, BufReader, BufRead};
use std::ops::Deref;
use std::sync::{Arc, Mutex, Condvar};
use std::sync::Arc;
use std::path::Path;
use std::fs::File;
use std::str::{FromStr, from_utf8};
@@ -82,7 +82,7 @@ use std::thread::sleep;
use std::time::Duration;
use rustc_serialize::hex::FromHex;
use ctrlc::CtrlC;
use util::{Lockable, H256, ToPretty, PayloadInfo, Bytes, Colour, Applyable, version, journaldb};
use util::{H256, ToPretty, PayloadInfo, Bytes, Colour, Applyable, version, journaldb};
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError,
ChainNotify, Mode};
@@ -93,6 +93,7 @@ use ethsync::EthSync;
use ethcore::miner::{Miner, MinerService, ExternalMiner};
use migration::migrate;
use informant::Informant;
use util::{Mutex, Condvar};
use die::*;
use cli::print_version;
@@ -593,7 +594,7 @@ fn wait_for_exit(
// Wait for signal
let mutex = Mutex::new(());
let _ = exit.wait(mutex.locked()).unwrap();
let _ = exit.wait(&mut mutex.lock());
info!("Finishing work, please wait...");
}