bitcoin_sync/
scoped_raw_mutex.rs

1crate::ix!();
2
3//TODO: is this correct? does this work?
4//does this create any deadlocks?
5//
6//I am using this to shim all of the calls to
7//CS_MAIN.lock() which the original c++ uses
8//throughout
9
10pub struct ScopedRawMutexGuard<'a> {
11
12    lock: &'a ScopedRawMutex,
13}
14
15impl<'a> ScopedRawMutexGuard<'a> {
16    pub fn new(x: &'a ScopedRawMutex) -> Self {
17        Self {
18            lock: x
19        }
20    }
21}
22
23impl<'a> Drop for ScopedRawMutexGuard<'a> {
24
25    fn drop(&mut self) {
26        unsafe { self.lock.0.unlock(); }
27    }
28}
29
30//---------------------------------------------
31pub struct ScopedRawMutex(RawMutex);
32
33impl Default for ScopedRawMutex {
34
35    fn default() -> Self {
36        Self(RawMutex::INIT)
37    }
38}
39
40impl ScopedRawMutex {
41
42    pub fn lock(&self) -> ScopedRawMutexGuard<'_> {
43        self.0.lock();
44        ScopedRawMutexGuard::new(self)
45    }
46}