cds  2.3.2
cds::sync::reentrant_spin_lock< Integral, Backoff > Class Template Reference

Recursive spin lock. More...

#include <cds/sync/spinlock.h>

Public Types

typedef Integral integral_type
 The integral type.
 
typedef Backoff backoff_strategy
 The backoff type.
 

Public Member Functions

 reentrant_spin_lock () noexcept
 Default constructor initializes spin to free (unlocked) state.
 
 reentrant_spin_lock (const reentrant_spin_lock< Integral, Backoff > &) noexcept
 Dummy copy constructor. More...
 
 reentrant_spin_lock (bool bLocked)
 Construct object in specified state.
 
 ~reentrant_spin_lock ()
 Dtor. Spin-lock must be unlocked.
 
bool is_locked () const noexcept
 Checks if the spin is locked. More...
 
bool try_lock () noexcept(noexcept(std::declval< reentrant_spin_lock >().try_acquire()))
 Try to lock the spin-lock.
 
bool try_lock (unsigned int nTryCount) noexcept(noexcept(std::declval< reentrant_spin_lock >().try_acquire(nTryCount)))
 Try to lock up to nTryCount attempts.
 
void lock () noexcept(noexcept(std::declval< reentrant_spin_lock >().acquire()))
 Lock the object waits if it is busy.
 
void unlock () noexcept
 Unlock the spin-lock.
 
void change_owner (OS::ThreadId newOwnerId) noexcept
 Change the owner of locked spin-lock. May be called by thread that owns spin-lock.
 

Private Types

typedef OS::ThreadId thread_id
 The type of thread id.
 

Detailed Description

template<typename Integral, class Backoff>
class cds::sync::reentrant_spin_lock< Integral, Backoff >

Recursive spin lock.

Allows recursive calls: the owner thread may recursive enter to critical section guarded by the spin-lock.

Template parameters:

  • Integral one of integral atomic type: unsigned int, int, and others
  • Backoff backoff strategy. Used when spin lock is locked

Constructor & Destructor Documentation

◆ reentrant_spin_lock()

template<typename Integral , class Backoff >
cds::sync::reentrant_spin_lock< Integral, Backoff >::reentrant_spin_lock ( const reentrant_spin_lock< Integral, Backoff > &  )
inlinenoexcept

Dummy copy constructor.

In theory, spin-lock cannot be copied. However, it is not practical. Therefore, we provide dummy copy constructor that do no copy in fact. The ctor initializes the spin to free (unlocked) state like default ctor.

Member Function Documentation

◆ is_locked()

template<typename Integral , class Backoff >
bool cds::sync::reentrant_spin_lock< Integral, Backoff >::is_locked ( ) const
inlinenoexcept

Checks if the spin is locked.

The spin is locked if lock count > 0 and the current thread is not an owner of the lock. Otherwise (i.e. lock count == 0 or the curren thread owns the spin) the spin is unlocked.


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:54 by Doxygen 1.8.13