DUDS
Distributed Update of Data from Something
duds::general::SpinlockYieldingWrapper Class Reference

A simple wrapper around a Spinlock object that implements the timed lockable concept such that attempts to lock an already locked Spinlock will always yield before trying again. More...

#include <Spinlock.hpp>

Inheritance diagram for duds::general::SpinlockYieldingWrapper:
Collaboration diagram for duds::general::SpinlockYieldingWrapper:

Public Member Functions

 SpinlockYieldingWrapper (Spinlock &l)
 
void lock ()
 
bool try_lock ()
 
template<class Rep , class Period >
bool try_lock_for (const std::chrono::duration< Rep, Period > &duration)
 
template<class Clock , class Duration >
bool try_lock_until (const std::chrono::time_point< Clock, Duration > &time)
 
void unlock ()
 

Private Attributes

Spinlocksl
 

Detailed Description

A simple wrapper around a Spinlock object that implements the timed lockable concept such that attempts to lock an already locked Spinlock will always yield before trying again.

This is useful in cases where a spinlock gives better performance a majority of the time, but seldom occuring longer delays are possible. This class can be used when those longer delays are known to occur to mitigate the performance issues of a spinlock. While functions for yielding exist on Spinlock, this class calls them from the lockable concept functions so that other classes like std::condition_variable_any can yield between lock attempts.

// something to lock
// the wrapper
// lock using the wrapper; std::unique_lock will now always
// yield, even on a host with multiple processors
Author
Jeff Jackowski

Definition at line 245 of file Spinlock.hpp.

Constructor & Destructor Documentation

◆ SpinlockYieldingWrapper()

duds::general::SpinlockYieldingWrapper::SpinlockYieldingWrapper ( Spinlock l)
inline

Definition at line 248 of file Spinlock.hpp.

Member Function Documentation

◆ lock()

void duds::general::SpinlockYieldingWrapper::lock ( )
inline

Definition at line 249 of file Spinlock.hpp.

◆ try_lock()

bool duds::general::SpinlockYieldingWrapper::try_lock ( )
inline

Definition at line 252 of file Spinlock.hpp.

◆ try_lock_for()

template<class Rep , class Period >
bool duds::general::SpinlockYieldingWrapper::try_lock_for ( const std::chrono::duration< Rep, Period > &  duration)
inline

Definition at line 260 of file Spinlock.hpp.

◆ try_lock_until()

template<class Clock , class Duration >
bool duds::general::SpinlockYieldingWrapper::try_lock_until ( const std::chrono::time_point< Clock, Duration > &  time)
inline

Definition at line 256 of file Spinlock.hpp.

◆ unlock()

void duds::general::SpinlockYieldingWrapper::unlock ( )
inline

Definition at line 263 of file Spinlock.hpp.

Member Data Documentation

◆ sl

Spinlock& duds::general::SpinlockYieldingWrapper::sl
private

Definition at line 246 of file Spinlock.hpp.


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