cds
2.3.2
|
Monitor that allocates node's lock when needed More...
#include <cds/sync/pool_monitor.h>
Data Structures | |
struct | node_injection |
Node injection. More... | |
Public Types | |
typedef LockPool | pool_type |
Pool type. | |
typedef pool_type::value_type | lock_type |
node lock type | |
typedef std::conditional< std::is_same< BackOff, cds::opt::none >::value, cds::backoff::yield, BackOff >::type | back_off |
back-off strategy for spinning | |
typedef uint32_t | refspin_type |
Reference counter + spin-lock bit. | |
typedef std::conditional< Stat, typename pool_monitor_traits::stat<>, typename pool_monitor_traits::empty_stat >::type | internal_stat |
Internal statistics. | |
template<typename Node > | |
using | scoped_lock = monitor_scoped_lock< pool_monitor, Node > |
Scoped lock. | |
Public Member Functions | |
pool_monitor () | |
Initializes the pool of 256 preallocated mutexes. | |
pool_monitor (size_t nPoolCapacity) | |
Initializes the pool of nPoolCapacity preallocated mutexes. | |
template<typename Node > | |
void | lock (Node const &p) const |
Makes exclusive access to node p . | |
template<typename Node > | |
void | unlock (Node const &p) const |
Unlocks the node p . | |
internal_stat const & | statistics () const |
Returns the reference to internal statistics. More... | |
Static Public Attributes | |
static constexpr size_t const | c_nDefaultCapacity = 256 |
Pool's default capacity. | |
Monitor that allocates node's lock when needed
The monitor is intended for reducing the number of system mutexes for huge containers like a tree. The monitor allocates the mutex from the pool LockPool
only when container's node should be locked. Lifetime of node's mutex is managed by reference counter. When the reference counter to node's mutex becomes zero, the mutex is given back to the pool.
The monitor is blocked: the access to node's mutex is performed under the spin-lock. However, node locking/unlocking is performed beyond the spin-lock.
Template arguments:
LockPool
- the pool type. The pool must maintain the objects of type std::mutex
or similar. The access to the pool is not synchronized.BackOff
- back-off strategy for spinning, default is cds::backoff::Default
Stat
- enable (true
) or disable (false
, the default) monitor's internal statistics.How to use
|
inline |
Returns the reference to internal statistics.
If class' template argument Stat
is false
, the function returns dummy statistics. Otherwise, it returns the reference to monitor's internal statistics of type pool_monitor_traits::stat.