mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Add timeouts to canonical head rwlock (#759)
* Add TimeoutRwLock to BeaconChain * Update network crate * Update rest api * Fix beacon chain tests * Fix rest api tests * Set test back to !debug_assertions
This commit is contained in:
20
beacon_node/beacon_chain/src/timeout_rw_lock.rs
Normal file
20
beacon_node/beacon_chain/src/timeout_rw_lock.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use std::time::Duration;
|
||||
|
||||
/// A simple wrapper around `parking_lot::RwLock` that only permits read/write access with a
|
||||
/// time-out (i.e., no indefinitely-blocking operations).
|
||||
pub struct TimeoutRwLock<T>(RwLock<T>);
|
||||
|
||||
impl<T> TimeoutRwLock<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self(RwLock::new(inner))
|
||||
}
|
||||
|
||||
pub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<T>> {
|
||||
self.0.try_read_for(timeout)
|
||||
}
|
||||
|
||||
pub fn try_write_for(&self, timeout: Duration) -> Option<RwLockWriteGuard<T>> {
|
||||
self.0.try_write_for(timeout)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user