Multithreaded event loop

This commit is contained in:
arkpar
2016-01-21 16:48:37 +01:00
parent 77d2303b55
commit e514d3d80f
17 changed files with 661 additions and 507 deletions

View File

@@ -30,11 +30,13 @@ impl EthashManager {
/// `nonce` - The nonce to pack into the mix
pub fn compute_light(&self, block_number: u64, header_hash: &H256, nonce: u64) -> ProofOfWork {
let epoch = block_number / ETHASH_EPOCH_LENGTH;
if !self.lights.read().unwrap().contains_key(&epoch) {
let mut lights = self.lights.write().unwrap(); // obtain write lock
if !lights.contains_key(&epoch) {
let light = Light::new(block_number);
lights.insert(epoch, light);
while !self.lights.read().unwrap().contains_key(&epoch) {
if let Ok(mut lights) = self.lights.try_write()
{
if !lights.contains_key(&epoch) {
let light = Light::new(block_number);
lights.insert(epoch, light);
}
}
}
self.lights.read().unwrap().get(&epoch).unwrap().compute(header_hash, nonce)