Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

immer::atom< T, MemoryPolicy > Class Template Reference

#include <atom.hpp>

Classes

struct  get_gc_atom_impl
 
struct  get_refcount_atom_impl
 

Public Types

using box_type = box< T, MemoryPolicy >
 
using value_type = T
 
using memory_policy = MemoryPolicy
 

Public Member Functions

 atom (const atom &)=delete
 
 atom (atom &&)=delete
 
void operator= (const atom &)=delete
 
void operator= (atom &&)=delete
 
 atom (box_type v={})
 
atomoperator= (box_type b)
 
 operator box_type () const
 
 operator value_type () const
 
box_type load () const
 
void store (box_type b)
 
box_type exchange (box_type b)
 
template<typename Fn >
box_type update (Fn &&fn)
 

Private Types

using impl_t = typename std::conditional_t< std::is_same< typename MemoryPolicy::refcount, no_refcount_policy >::value, get_gc_atom_impl, get_refcount_atom_impl >::template apply< T, MemoryPolicy >::type
 

Private Attributes

impl_t impl_
 

Detailed Description

template<typename T, typename MemoryPolicy = default_memory_policy>
class immer::atom< T, MemoryPolicy >

Stores for boxed values of type T in a thread-safe manner.

See also
box

.. warning:: If memory policy used includes thread unsafe reference counting, no no thread safety is assumed, and the atom becomes thread unsafe too!

.. note:: box<T> provides a value based box of type T, this is, we can think about it as a value-based version of std::shared_ptr. In a similar fashion, atom<T> is in spirit the value-based equivalent of C++20 std::atomic_shared_ptr. However, the API does not follow std::atomic interface closely, since it attempts to be a higher level construction, most similar to Clojure's (atom). It is remarkable in particular that, since box<T> underlying object is immutable, using atom<T> is fully thread-safe in ways that std::atmic_shared_ptr is not. This is so because dereferencing the underlying pointer in a std::atomic_share_ptr may require further synchronization, in particular when invoking non-const methods.

Definition at line 154 of file atom.hpp.

Member Typedef Documentation

◆ box_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::atom< T, MemoryPolicy >::box_type = box<T, MemoryPolicy>

Definition at line 157 of file atom.hpp.

◆ impl_t

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::atom< T, MemoryPolicy >::impl_t = typename std::conditional_t< std::is_same<typename MemoryPolicy::refcount, no_refcount_policy>::value, get_gc_atom_impl, get_refcount_atom_impl >::template apply<T, MemoryPolicy>::type
private

Definition at line 254 of file atom.hpp.

◆ memory_policy

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::atom< T, MemoryPolicy >::memory_policy = MemoryPolicy

Definition at line 159 of file atom.hpp.

◆ value_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::atom< T, MemoryPolicy >::value_type = T

Definition at line 158 of file atom.hpp.

Constructor & Destructor Documentation

◆ atom() [1/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::atom< T, MemoryPolicy >::atom ( const atom< T, MemoryPolicy > &  )
delete

◆ atom() [2/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::atom< T, MemoryPolicy >::atom ( atom< T, MemoryPolicy > &&  )
delete

◆ atom() [3/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::atom< T, MemoryPolicy >::atom ( box_type  v = {})
inline

Constructs an atom holding a value b;

Definition at line 169 of file atom.hpp.

Member Function Documentation

◆ exchange()

template<typename T , typename MemoryPolicy = default_memory_policy>
box_type immer::atom< T, MemoryPolicy >::exchange ( box_type  b)
inline

Stores a new value and returns the old value, in a thread-safe manner.

Definition at line 209 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ load()

template<typename T , typename MemoryPolicy = default_memory_policy>
box_type immer::atom< T, MemoryPolicy >::load ( ) const
inline

Reads the currently stored value in a thread-safe manner.

Definition at line 197 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ operator box_type()

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::atom< T, MemoryPolicy >::operator box_type ( ) const
inline

Reads the currently stored value in a thread-safe manner.

Definition at line 185 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ operator value_type()

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::atom< T, MemoryPolicy >::operator value_type ( ) const
inline

Reads the currently stored value in a thread-safe manner.

Definition at line 191 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ operator=() [1/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
void immer::atom< T, MemoryPolicy >::operator= ( const atom< T, MemoryPolicy > &  )
delete

◆ operator=() [2/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
void immer::atom< T, MemoryPolicy >::operator= ( atom< T, MemoryPolicy > &&  )
delete

◆ operator=() [3/3]

template<typename T , typename MemoryPolicy = default_memory_policy>
atom& immer::atom< T, MemoryPolicy >::operator= ( box_type  b)
inline

Sets a new value in the atom.

Definition at line 176 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ store()

template<typename T , typename MemoryPolicy = default_memory_policy>
void immer::atom< T, MemoryPolicy >::store ( box_type  b)
inline

Stores a new value in a thread-safe manner.

Definition at line 203 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

◆ update()

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename Fn >
box_type immer::atom< T, MemoryPolicy >::update ( Fn &&  fn)
inline

Stores the result of applying fn to the current value atomically and returns the new resulting value.

.. warning:: fn must be a pure function and have no side effects! The function might be evaluated multiple times when multiple threads content to update the value.

Definition at line 225 of file atom.hpp.

References immer::atom< T, MemoryPolicy >::impl_.

Member Data Documentation

◆ impl_


The documentation for this class was generated from the following file:
Released under the MIT license