Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Namespaces | Macros | Typedefs
Guards.h File Reference
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <boost/thread.hpp>
Include dependency graph for Guards.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dev::GenericGuardBool< GuardType, MutexType >
 
struct  dev::GenericUnguardBool< MutexType >
 
struct  dev::GenericUnguardSharedBool< MutexType >
 
class  dev::SpinLock
 Simple lock that waits for release without making context switch. More...
 
class  dev::Notified< N >
 

Namespaces

 dev
 Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Originally by RenĂ© Nyffenegger.
 

Macros

#define DEV_GUARDED(MUTEX)   for (GenericGuardBool<Guard, Mutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 Simple block guard. More...
 
#define DEV_READ_GUARDED(MUTEX)   for (GenericGuardBool<ReadGuard, SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 
#define DEV_WRITE_GUARDED(MUTEX)   for (GenericGuardBool<WriteGuard, SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 
#define DEV_RECURSIVE_GUARDED(MUTEX)   for (GenericGuardBool<RecursiveGuard, RecursiveMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 
#define DEV_UNGUARDED(MUTEX)   for (GenericUnguardBool<Mutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 
#define DEV_READ_UNGUARDED(MUTEX)   for (GenericUnguardSharedBool<SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 
#define DEV_WRITE_UNGUARDED(MUTEX)   for (GenericUnguardBool<SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
 

Typedefs

using dev::Mutex = std::mutex
 
using dev::RecursiveMutex = std::recursive_mutex
 
using dev::SharedMutex = boost::shared_mutex
 
using dev::Guard = std::lock_guard< std::mutex >
 
using dev::UniqueGuard = std::unique_lock< std::mutex >
 
using dev::RecursiveGuard = std::lock_guard< std::recursive_mutex >
 
using dev::ReadGuard = boost::shared_lock< boost::shared_mutex >
 
using dev::UpgradableGuard = boost::upgrade_lock< boost::shared_mutex >
 
using dev::UpgradeGuard = boost::upgrade_to_unique_lock< boost::shared_mutex >
 
using dev::WriteGuard = boost::unique_lock< boost::shared_mutex >
 
using dev::SpinGuard = std::lock_guard< SpinLock >
 

Detailed Description

Author
Gav Wood i@gav.nosp@m.wood.nosp@m..com
Date
2014

Definition in file Guards.h.

Macro Definition Documentation

#define DEV_GUARDED (   MUTEX)    for (GenericGuardBool<Guard, Mutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Simple block guard.

The expression/block following is guarded though the given mutex. Usage:

1 Mutex m;
2 unsigned d;
3 ...
4 ETH_(m) d = 1;
5 ...
6 ETH_(m) { for (auto d = 10; d > 0; --d) foo(d); d = 0; }

There are several variants of this basic mechanism for different Mutex types and Guards.

There is also the UNGUARD variant which allows an unguarded expression/block to exist within a guarded expression. eg:

1 Mutex m;
2 int d;
3 ...
4 ETH_GUARDED(m)
5 {
6  for (auto d = 50; d > 25; --d)
7  foo(d);
8  ETH_UNGUARDED(m)
9  bar();
10  for (; d > 0; --d)
11  foo(d);
12 }

Definition at line 144 of file Guards.h.

#define DEV_READ_GUARDED (   MUTEX)    for (GenericGuardBool<ReadGuard, SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 146 of file Guards.h.

#define DEV_READ_UNGUARDED (   MUTEX)    for (GenericUnguardSharedBool<SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 154 of file Guards.h.

#define DEV_RECURSIVE_GUARDED (   MUTEX)    for (GenericGuardBool<RecursiveGuard, RecursiveMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 150 of file Guards.h.

#define DEV_UNGUARDED (   MUTEX)    for (GenericUnguardBool<Mutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 152 of file Guards.h.

#define DEV_WRITE_GUARDED (   MUTEX)    for (GenericGuardBool<WriteGuard, SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 148 of file Guards.h.

#define DEV_WRITE_UNGUARDED (   MUTEX)    for (GenericUnguardBool<SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)

Definition at line 156 of file Guards.h.