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::ordered_spinlockbase< T > Struct Template Reference

#include "spinlock.hpp"

Classes

union  _internals
 

Public Types

typedef T value_type
 

Public Member Functions

constexpr ordered_spinlockbase () noexcept
 
 ordered_spinlockbase (const ordered_spinlockbase &)=delete
 
 ordered_spinlockbase (ordered_spinlockbase &&) noexcept
 Atomically move constructs.
 
 ~ordered_spinlockbase ()
 
ordered_spinlockbaseoperator= (const ordered_spinlockbase &)=delete
 
ordered_spinlockbaseoperator= (ordered_spinlockbase &&)=delete
 
constexpr T load (memory_order o=memory_order_seq_cst) const noexcept
 Returns the raw atomic.
 
void store (T a, memory_order o=memory_order_seq_cst) noexcept
 Sets the raw atomic.
 
bool try_lock () noexcept
 Tries to lock the spinlock, returning true if successful.
 
void unlock () noexcept
 Releases the lock.
 
bool int_yield (size_t) noexcept
 

Protected Types

using _halfT = typename detail::choose_half_type< value_type >::type
 

Protected Member Functions

value_type _begin_try_lock () noexcept
 
bool _try_lock (value_type &state) noexcept
 

Protected Attributes

atomic< value_type_v
 

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::value_type

◆ _halfT

template<typename T >
using quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::_halfT = typename detail::choose_half_type<value_type>::type
protected

Constructor & Destructor Documentation

◆ ordered_spinlockbase() [1/3]

template<typename T >
constexpr quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::ordered_spinlockbase ( )
inlineconstexprnoexcept
362 : _v(0)
363 {
365 // v.store(0, memory_order_release);
366 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p)
Definition config.hpp:102
atomic< value_type > _v
Definition spinlock.hpp:338

◆ ordered_spinlockbase() [2/3]

template<typename T >
quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::ordered_spinlockbase ( const ordered_spinlockbase< T > &  )
delete

◆ ordered_spinlockbase() [3/3]

template<typename T >
quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::ordered_spinlockbase ( ordered_spinlockbase< T > &&  )
inlinenoexcept

Atomically move constructs.

370 : _v(0)
371 {
373 // v.store(o.v.exchange(0, memory_order_acq_rel));
374 // v.store(0, memory_order_release);
375 }

◆ ~ordered_spinlockbase()

377 {
378#ifdef QUICKCPPLIB_ENABLE_VALGRIND
379 _internals i = {_v.load(memory_order_relaxed)};
380 if(i.entry != i.exit)
381 {
383 }
384#endif
386 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p)
Definition config.hpp:103
#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s)
Definition config.hpp:105

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
ordered_spinlockbase & quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::operator= ( const ordered_spinlockbase< T > &  )
delete

◆ operator=() [2/2]

◆ load()

template<typename T >
constexpr T quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::load ( memory_order  o = memory_order_seq_cst) const
inlineconstexprnoexcept

Returns the raw atomic.

390{ return _v.load(o); }

◆ store()

template<typename T >
void quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::store ( a,
memory_order  o = memory_order_seq_cst 
)
inlinenoexcept

Sets the raw atomic.

392{ _v.store(a, o); }

◆ try_lock()

template<typename T >
bool quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::try_lock ( )
inlinenoexcept

Tries to lock the spinlock, returning true if successful.

396 {
397 _internals i = {_v.load(memory_order_relaxed)}, o = i;
398 // If locked, bail out immediately
399 if(i.entry != i.exit)
400 return false;
401 o.entry++;
402 if(_v.compare_exchange_weak(i.uint, o.uint, memory_order_acquire, memory_order_relaxed))
403 {
405 return true;
406 }
407 return false;
408 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s)
Definition config.hpp:104

◆ _begin_try_lock()

template<typename T >
value_type quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::_begin_try_lock ( )
inlineprotectednoexcept
411{ return _v.load(memory_order_relaxed); }

◆ _try_lock()

template<typename T >
bool quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::_try_lock ( value_type state)
inlineprotectednoexcept
413 {
414 _internals i = {state}, o;
415 o = i;
416 o.entry++;
417 if(_v.compare_exchange_weak(i.uint, o.uint, memory_order_acquire, memory_order_relaxed))
418 {
420 return true;
421 }
422 state = i.uint;
423 return false;
424 }

◆ unlock()

template<typename T >
void quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::unlock ( )
inlinenoexcept

Releases the lock.

429 {
431 _internals i = {_v.load(memory_order_relaxed)}, o;
432 for(;;)
433 {
434 o = i;
435 o.exit++;
436 if(_v.compare_exchange_weak(i.uint, o.uint, memory_order_release, memory_order_relaxed))
437 return;
438 }
439 }

◆ int_yield()

template<typename T >
bool quickcpplib::_xxx::configurable_spinlock::ordered_spinlockbase< T >::int_yield ( size_t  )
inlinenoexcept
440{ return false; }

Member Data Documentation

◆ _v


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