QuickCppLib 0.10
Eliminate all the tedious hassle when making state-of-the-art C++ 14 - 23 libraries!
Loading...
Searching...
No Matches
quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 > Class Template Reference

A non-FIFO policy configurable shared/exclusive spin lock meeting the SharedMutex concept. More...

#include "spinlock.hpp"

Inheritance diagram for quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >:
quickcpplib::_xxx::configurable_spinlock::spins_to_sleep::policy< parenttype >

Public Member Functions

constexpr shared_spinlock ()
 shared_spinlock (const shared_spinlock &)=delete
 shared_spinlock (shared_spinlock &&o) noexcept
void lock () noexcept
 Locks the spinlock for exclusive access.
void lock_shared () noexcept
 Locks the spinlock for shared access.
constexpr bool int_yield (size_t n) noexcept

Detailed Description

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
class quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >

A non-FIFO policy configurable shared/exclusive spin lock meeting the SharedMutex concept.

Template Parameters
TAn unsigned integral type capable of atomic usage

sizeof(shared_spinlock<T>) == sizeof(T). Suitable for usage in shared memory.

Implementing a fair shared spin lock with acceptable performance in just four bytes of storage is challenging, so this is a reader-biased shared lock which uses bit 0 as the exclusion bit, and the remainder of the bits to track how many readers are in the shared lock. Undefined behaviour will occur if the number of concurrent readers exceeds half the maximum value of a T.

Maximum performance on Intel for exclusive locks is the same as a spinlock<uintptr_t>. For shared locks it is roughly one third that of spinlock<uintptr_t> due to performing twice as many atomic read-modify-updates.

Constructor & Destructor Documentation

◆ shared_spinlock() [1/3]

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >::shared_spinlock ( )
inlineconstexpr
792{}

◆ shared_spinlock() [2/3]

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >::shared_spinlock ( const shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 > & )
delete

◆ shared_spinlock() [3/3]

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >::shared_spinlock ( shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 > && o)
inlinenoexcept
795 : parenttype(std::move(o))
796 {
797 }
A non-FIFO policy configurable shared/exclusive spin lock meeting the SharedMutex concept.
Definition spinlock.hpp:788

Member Function Documentation

◆ lock()

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
void quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >::lock ( )
inlinenoexcept

Locks the spinlock for exclusive access.

800 {
801 for(size_t n = 0;; n++)
802 {
804 return;
806 }
807 }

◆ lock_shared()

template<typename T = uintptr_t, template< class > class spinpolicy2 = spins_to_loop<125>::policy, template< class > class spinpolicy3 = spins_to_yield<250>::policy, template< class > class spinpolicy4 = spins_to_sleep::policy>
void quickcpplib::_xxx::configurable_spinlock::shared_spinlock< T, spinpolicy2, spinpolicy3, spinpolicy4 >::lock_shared ( )
inlinenoexcept

Locks the spinlock for shared access.

810 {
811 for(size_t n = 0;; n++)
812 {
814 return;
816 }
817 }

◆ int_yield()

template<class parenttype>
bool quickcpplib::_xxx::configurable_spinlock::spins_to_sleep::policy< parenttype >::int_yield ( size_t n)
inlineconstexprnoexceptinherited
645 {
647 return true;
649 return true;
650 }

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