swift
Loading...
Searching...
No Matches
swift::misc::LockFree< T > Class Template Reference

Lock-free wrapper for synchronizing multi-threaded access to an object. More...

#include <lockfree.h>

Public Member Functions

 LockFree ()=default
 Default constructor. Object will contain a default-constructed T.
 LockFree (const T &other)
 Construct by copying from a T.
 LockFree (T &&other) noexcept(std::is_nothrow_move_assignable_v< T >)
 Construct by moving from a T.
LockFreeReader< const T > read () const
 Return an object which can read the current value.
LockFreeUniqueWriter< T > uniqueWrite ()
 Return an object which can write a new value, as long as there are no other writes.
template<typename F>
auto read (F &&inspector)
 Pass the current value to the functor inspector, and return whatever inspector returns.
template<typename F>
void uniqueWrite (F &&mutator)
 Pass a modifiable reference to the functor mutator. Unsafe if there are multiple writers.
 LockFree (const LockFree &)=delete
 LockFree cannot be copied or moved.
LockFree & operator= (const LockFree &)=delete
 LockFree cannot be copied or moved.
 LockFree (LockFree &&)=delete
 LockFree cannot be copied or moved.
LockFree & operator= (LockFree &&)=delete
 LockFree cannot be copied or moved.

Detailed Description

template<typename T>
class swift::misc::LockFree< T >

Lock-free wrapper for synchronizing multi-threaded access to an object.

Implemented using atomic operations of std::shared_ptr.

Definition at line 147 of file lockfree.h.

Constructor & Destructor Documentation

◆ LockFree() [1/2]

template<typename T>
swift::misc::LockFree< T >::LockFree ( const T & other)
inline

Construct by copying from a T.

Definition at line 154 of file lockfree.h.

◆ LockFree() [2/2]

template<typename T>
swift::misc::LockFree< T >::LockFree ( T && other)
inlinenoexcept

Construct by moving from a T.

Definition at line 157 of file lockfree.h.

Member Function Documentation

◆ read() [1/2]

template<typename T>
LockFreeReader< const T > swift::misc::LockFree< T >::read ( ) const
inline

Return an object which can read the current value.

Definition at line 173 of file lockfree.h.

◆ read() [2/2]

template<typename T>
template<typename F>
auto swift::misc::LockFree< T >::read ( F && inspector)
inline

Pass the current value to the functor inspector, and return whatever inspector returns.

Definition at line 185 of file lockfree.h.

◆ uniqueWrite() [1/2]

template<typename T>
LockFreeUniqueWriter< T > swift::misc::LockFree< T >::uniqueWrite ( )
inline

Return an object which can write a new value, as long as there are no other writes.

Definition at line 180 of file lockfree.h.

◆ uniqueWrite() [2/2]

template<typename T>
template<typename F>
void swift::misc::LockFree< T >::uniqueWrite ( F && mutator)
inline

Pass a modifiable reference to the functor mutator. Unsafe if there are multiple writers.

Definition at line 192 of file lockfree.h.


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