Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Make sure parking_lot::Condvar is signaled under a mutex #1730

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/tests
Submodule tests updated 51 files
+0 −8 .travis.yml
+13 −13 BlockchainTests/Homestead/bcBlockGasLimitTest.json
+1,807 −1,807 BlockchainTests/Homestead/bcForkStressTest.json
+210 −210 BlockchainTests/Homestead/bcGasPricerTest.json
+21 −21 BlockchainTests/Homestead/bcInvalidHeaderTest.json
+460 −460 BlockchainTests/Homestead/bcMultiChainTest.json
+248 −248 BlockchainTests/Homestead/bcRPC_API_Test.json
+106 −106 BlockchainTests/Homestead/bcStateTest.json
+852 −852 BlockchainTests/Homestead/bcTotalDifficultyTest.json
+206 −861 BlockchainTests/Homestead/bcUncleHeaderValiditiy.json
+572 −572 BlockchainTests/Homestead/bcUncleTest.json
+139 −139 BlockchainTests/Homestead/bcValidBlockTest.json
+2,249 −2,249 BlockchainTests/Homestead/bcWalletTest.json
+0 −8,599 BlockchainTests/TestNetwork/bcTheDaoTest.json
+13 −431 BlockchainTests/bcBlockGasLimitTest.json
+1,833 −1,833 BlockchainTests/bcForkStressTest.json
+210 −210 BlockchainTests/bcGasPricerTest.json
+21 −80 BlockchainTests/bcInvalidHeaderTest.json
+452 −452 BlockchainTests/bcMultiChainTest.json
+215 −215 BlockchainTests/bcRPC_API_Test.json
+24 −182 BlockchainTests/bcStateTest.json
+808 −808 BlockchainTests/bcTotalDifficultyTest.json
+194 −194 BlockchainTests/bcUncleHeaderValiditiy.json
+572 −572 BlockchainTests/bcUncleTest.json
+139 −139 BlockchainTests/bcValidBlockTest.json
+2,244 −2,244 BlockchainTests/bcWalletTest.json
+0 −3,310 StateTests/Homestead/stBoundsTest.json
+245 −218 StateTests/Homestead/stCallCodes.json
+15 −15 StateTests/Homestead/stCallCreateCallCodeTest.json
+216 −192 StateTests/Homestead/stCallDelegateCodes.json
+247 −217 StateTests/Homestead/stCallDelegateCodesCallCode.json
+18 −18 StateTests/Homestead/stDelegatecallTest.json
+10 −32 StateTests/Homestead/stLogTests.json
+4 −943 StateTests/Homestead/stMemoryStressTest.json
+2 −2 StateTests/Homestead/stSpecialTest.json
+2 −2 StateTests/Homestead/stSystemOperationsTest.json
+9 −146 StateTests/Homestead/stTransactionTest.json
+255 −227 StateTests/stCallCodes.json
+12 −12 StateTests/stCallCreateCallCodeTest.json
+10 −32 StateTests/stLogTests.json
+3 −4 StateTests/stMemoryStressTest.json
+2 −2 StateTests/stSpecialTest.json
+9 −64 StateTests/stTransactionTest.json
+38 −118 TransactionTests/Homestead/ttTransactionTest.json
+4 −84 TransactionTests/ttTransactionTest.json
+8 −8 VMTests/vmArithmeticTest.json
+38 −39 VMTests/vmBitwiseLogicOperationTest.json
+4 −4 VMTests/vmEnvironmentalInfoTest.json
+12 −49 VMTests/vmIOandFlowOperationsTest.json
+8 −30 VMTests/vmLogTest.json
+2 −2 VMTests/vmPushDupSwapTest.json
10 changes: 7 additions & 3 deletions ethcore/src/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ impl BlockQueue {
match verify_block_basic(&header, &bytes, self.engine.deref().deref()) {
Ok(()) => {
self.processing.write().insert(h.clone());
self.verification.unverified.lock().push_back(UnverifiedBlock { header: header, bytes: bytes });
let mut unverified = self.verification.unverified.lock();
unverified.push_back(UnverifiedBlock { header: header, bytes: bytes });
self.more_to_verify.notify_all();
Ok(h)
},
Expand Down Expand Up @@ -432,8 +433,11 @@ impl Drop for BlockQueue {
fn drop(&mut self) {
trace!(target: "shutdown", "[BlockQueue] Closing...");
self.clear();
self.deleting.store(true, AtomicOrdering::Release);
self.more_to_verify.notify_all();
{
let _ = self.verification.unverified.lock();
self.deleting.store(true, AtomicOrdering::Release);
self.more_to_verify.notify_all();
}
for t in self.verifiers.drain(..) {
t.join().unwrap();
}
Expand Down
5 changes: 4 additions & 1 deletion util/src/io/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ pub struct IoManager<Message> where Message: Send + Sync {
workers: Vec<Worker>,
worker_channel: chase_lev::Worker<Work<Message>>,
work_ready: Arc<Condvar>,
work_mutex: Arc<Mutex<()>>,
}

impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
/// Creates a new instance and registers it with the event loop.
pub fn start(panic_handler: Arc<PanicHandler>, event_loop: &mut EventLoop<IoManager<Message>>) -> Result<(), UtilError> {
let (worker, stealer) = chase_lev::deque();
let num_workers = 4;
let work_ready_mutex = Arc::new(Mutex::new(()));
let work_ready_mutex = Arc::new(Mutex::new(()));
let work_ready = Arc::new(Condvar::new());
let workers = (0..num_workers).map(|i|
Worker::new(
Expand All @@ -196,6 +197,7 @@ impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
worker_channel: worker,
workers: workers,
work_ready: work_ready,
work_mutex: work_ready_mutex,
};
try!(event_loop.run(&mut io));
Ok(())
Expand All @@ -221,6 +223,7 @@ impl<Message> Handler for IoManager<Message> where Message: Send + Clone + Sync
self.worker_channel.push(Work { work_type: WorkType::Writable, token: token_id, handler: handler.clone(), handler_id: handler_index });
}
}
let _ = self.work_mutex.lock();
self.work_ready.notify_all();
}
}
Expand Down
7 changes: 5 additions & 2 deletions util/src/io/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ impl Drop for Worker {
fn drop(&mut self) {
trace!(target: "shutdown", "[IoWorker] Closing...");
let _ = self.wait_mutex.lock();
self.deleting.store(true, AtomicOrdering::Release);
self.wait.notify_all();
{
let _ = self.wait_mutex.lock();
self.deleting.store(true, AtomicOrdering::Release);
self.wait.notify_all();
}
let thread = mem::replace(&mut self.thread, None).unwrap();
thread.join().ok();
trace!(target: "shutdown", "[IoWorker] Closed");
Expand Down