BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
Classes | Macros | Typedefs
sync.h File Reference
#include <threadsafety.h>
#include <condition_variable>
#include <thread>
#include <mutex>
Include dependency graph for sync.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  AnnotatedMixin< PARENT >
 Template mixin that adds -Wthread-safety locking annotations and lock order checking to a subset of the mutex API. More...
 
class  UniqueLock< Mutex, Base >
 Wrapper around std::unique_lock style lock for Mutex. More...
 
class  CSemaphore
 
class  CSemaphoreGrant
 RAII-style semaphore lock. More...
 

Macros

#define AssertLockHeld(cs)   AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
 
#define AssertLockNotHeld(cs)   AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)
 
#define PASTE(x, y)   x ## y
 
#define PASTE2(x, y)   PASTE(x, y)
 
#define LOCK(cs)   DebugLock<decltype(cs)> PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__)
 
#define LOCK2(cs1, cs2)
 
#define TRY_LOCK(cs, name)   DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__, true)
 
#define WAIT_LOCK(cs, name)   DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__)
 
#define ENTER_CRITICAL_SECTION(cs)
 
#define LEAVE_CRITICAL_SECTION(cs)
 

Typedefs

typedef AnnotatedMixin< std::recursive_mutex > CCriticalSection
 Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the recursive lock by default. More...
 
typedef AnnotatedMixin< std::mutex > Mutex
 Wrapped mutex: supports waiting but not recursive locking. More...
 
template<typename MutexArg >
using DebugLock = UniqueLock< typename std::remove_reference< typename std::remove_pointer< MutexArg >::type >::type >
 

Macro Definition Documentation

◆ AssertLockHeld

#define AssertLockHeld (   cs)    AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)

Definition at line 70 of file sync.h.

◆ AssertLockNotHeld

#define AssertLockNotHeld (   cs)    AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)

Definition at line 71 of file sync.h.

◆ ENTER_CRITICAL_SECTION

#define ENTER_CRITICAL_SECTION (   cs)
Value:
{ \
EnterCritical(#cs, __FILE__, __LINE__, (void*)(&cs)); \
(cs).lock(); \
}

Definition at line 188 of file sync.h.

◆ LEAVE_CRITICAL_SECTION

#define LEAVE_CRITICAL_SECTION (   cs)
Value:
{ \
(cs).unlock(); \
LeaveCritical(); \
}

Definition at line 194 of file sync.h.

◆ LOCK

#define LOCK (   cs)    DebugLock<decltype(cs)> PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__)

Definition at line 181 of file sync.h.

◆ LOCK2

#define LOCK2 (   cs1,
  cs2 
)
Value:
DebugLock<decltype(cs1)> criticalblock1(cs1, #cs1, __FILE__, __LINE__); \
DebugLock<decltype(cs2)> criticalblock2(cs2, #cs2, __FILE__, __LINE__);
Wrapper around std::unique_lock style lock for Mutex.
Definition: sync.h:118

Definition at line 182 of file sync.h.

◆ PASTE

#define PASTE (   x,
 
)    x ## y

Definition at line 178 of file sync.h.

◆ PASTE2

#define PASTE2 (   x,
 
)    PASTE(x, y)

Definition at line 179 of file sync.h.

◆ TRY_LOCK

#define TRY_LOCK (   cs,
  name 
)    DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__, true)

Definition at line 185 of file sync.h.

◆ WAIT_LOCK

#define WAIT_LOCK (   cs,
  name 
)    DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__)

Definition at line 186 of file sync.h.

Typedef Documentation

◆ CCriticalSection

typedef AnnotatedMixin<std::recursive_mutex> CCriticalSection

Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the recursive lock by default.

Definition at line 107 of file sync.h.

◆ DebugLock

template<typename MutexArg >
using DebugLock = UniqueLock<typename std::remove_reference<typename std::remove_pointer<MutexArg>::type>::type>

Definition at line 176 of file sync.h.

◆ Mutex

typedef AnnotatedMixin<std::mutex> Mutex

Wrapped mutex: supports waiting but not recursive locking.

Definition at line 110 of file sync.h.