cds  2.3.2
cds::sync::lock_array< Lock, SelectPolicy, Alloc > Class Template Reference

Array of locks. More...

#include <cds/sync/lock_array.h>

Public Types

typedef Lock lock_type
 lock type
 
typedef SelectPolicy select_cell_policy
 Cell selection policy functor.
 

Public Member Functions

 lock_array (size_t nCapacity)
 Constructs array of locks. More...
 
 lock_array (size_t nCapacity, select_cell_policy const &policy)
 Constructs array of lock and copy cell selection policy. More...
 
 lock_array (size_t nCapacity, select_cell_policy &&policy)
 Constructs array of lock and move cell selection policy. More...
 
 ~lock_array ()
 Destructs array of locks and frees used memory.
 
template<typename Q >
size_t lock (Q const &hint)
 Locks a lock at cell hint. More...
 
template<typename Q >
size_t try_lock (Q const &hint)
 Try lock a lock at cell hint. More...
 
void unlock (size_t nCell)
 Unlock the lock specified by index nCell.
 
void lock_all ()
 Lock all.
 
void unlock_all ()
 Unlock all.
 
lock_typeat (size_t nCell) const
 Get lock at cell nCell. More...
 
size_t size () const
 Size of lock array.
 

Static Public Attributes

static size_t const c_nUnspecifiedCell = (size_t) -1
 failed try_lock call result
 

Protected Attributes

lock_typem_arrLocks
 lock array
 
size_t const m_nCapacity
 array capacity
 
select_cell_policy m_SelectCellPolicy
 Cell selection policy.
 

Detailed Description

template<typename Lock, typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
class cds::sync::lock_array< Lock, SelectPolicy, Alloc >

Array of locks.

The lock array is useful for building fine-grained lock-based data structure based on striping technique. Instead of locking access to data struct (a hash map, for example) at whole, the striping locks only part of the map (a bucket). So, access to different buckets can be simultaneous.

Template arguments:

To determine array's cell the selection policy SelectPolicy functor is used. Two arguments are passed to the policy:

size_t operator()( size_t nHint, size_t nCapacity ) const
  • nHint - a hint to calculate cell index in the lock array. Usually, it is a hash value.
  • nCapacity - the size of the lock array The functor should return the index in the lock array.

Note that the type of nHint parameter can be any.

Constructor & Destructor Documentation

◆ lock_array() [1/3]

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
cds::sync::lock_array< Lock, SelectPolicy, Alloc >::lock_array ( size_t  nCapacity)
inline

Constructs array of locks.

Allocates the array and initializes all locks as unlocked.

Parameters
[in]nCapacityArray size

◆ lock_array() [2/3]

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
cds::sync::lock_array< Lock, SelectPolicy, Alloc >::lock_array ( size_t  nCapacity,
select_cell_policy const &  policy 
)
inline

Constructs array of lock and copy cell selection policy.

Allocates the array and initializes all locks as unlocked.

Parameters
[in]nCapacityArray size
policyCell selection policy (copy-constructible)

◆ lock_array() [3/3]

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
cds::sync::lock_array< Lock, SelectPolicy, Alloc >::lock_array ( size_t  nCapacity,
select_cell_policy &&  policy 
)
inline

Constructs array of lock and move cell selection policy.

Allocates the array and initializes all locks as unlocked.

Parameters
[in]nCapacityArray size
policyCell selection policy (move-constructible)

Member Function Documentation

◆ at()

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
lock_type& cds::sync::lock_array< Lock, SelectPolicy, Alloc >::at ( size_t  nCell) const
inline

Get lock at cell nCell.

Precondition: nCell < size()

◆ lock()

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
template<typename Q >
size_t cds::sync::lock_array< Lock, SelectPolicy, Alloc >::lock ( Q const &  hint)
inline

Locks a lock at cell hint.

To define real array's cell which should be locked, select_cell_policy is used. The target cell is a result of select_cell_policy( hint, size()).

Returns the index of locked lock.

◆ try_lock()

template<typename Lock , typename SelectPolicy = mod_select_policy, class Alloc = CDS_DEFAULT_ALLOCATOR>
template<typename Q >
size_t cds::sync::lock_array< Lock, SelectPolicy, Alloc >::try_lock ( Q const &  hint)
inline

Try lock a lock at cell hint.

To define real array's cell which should be locked, select_cell_policy is used. The target cell is a result of select_cell_policy( hint, size()).

Returns the index of locked lock if success, c_nUnspecifiedCell constant otherwise.


The documentation for this class was generated from the following file:

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:53 by Doxygen 1.8.13