HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
v1::rcu< T, Allocator > Class Template Reference

#include <hikogui/rcu.hpp>

Public Types

using value_type = T
 
using allocator_type = Allocator
 

Public Member Functions

constexpr rcu (allocator_type allocator=allocator_type{}) noexcept
 Construct a new rcu object.
 
 rcu (rcu const &)=delete
 
 rcu (rcu &&)=delete
 
rcuoperator= (rcu const &)=delete
 
rcuoperator= (rcu &&)=delete
 
void read_lock () noexcept
 Lock the rcu pointer for reading.
 
void read_unlock () noexcept
 Unlock the rcu pointer for reading.
 
void write_lock () noexcept
 Lock the rcu pointer for writing.
 
void write_unlock () noexcept
 Unlock the rcu pointer for writing.
 
value_type const * get () noexcept
 get the rcu-pointer.
 
value_type const * unsafe_get () noexcept
 Derefence the rcu-pointer.
 
uint64_t version () const noexcept
 The version of the lock.
 
size_t capacity () const noexcept
 Number of object that are currently allocated.
 
value_type * exchange (value_type *ptr) noexcept
 Exchange the rcu-pointers.
 
value_type * copy () const noexcept
 Create a copy of the value.
 
template<typename... Args>
void emplace (Args &&...args) noexcept
 Emplace a new value.
 
bool empty () const noexcept
 
 operator bool () const noexcept
 
void reset () noexcept
 
rcuoperator= (nullptr_t) noexcept
 
void add_old_copy (uint64_t old_version, value_type *old_ptr) noexcept
 Add an old copy.
 

Detailed Description

template<typename T, typename Allocator = std::allocator<T>>
class v1::rcu< T, Allocator >

Read-copy-update.

Template Parameters
TThe type managed by RCU.
AllocatorThe allocator used to allocate objects of type T.

Constructor & Destructor Documentation

◆ rcu()

template<typename T , typename Allocator = std::allocator<T>>
constexpr v1::rcu< T, Allocator >::rcu ( allocator_type allocator = allocator_type{})
inlineconstexprnoexcept

Construct a new rcu object.

Note
The initial rcu will be a nullptr.
Parameters
allocatorThe allocator to use.

Member Function Documentation

◆ add_old_copy()

template<typename T , typename Allocator = std::allocator<T>>
void v1::rcu< T, Allocator >::add_old_copy ( uint64_t old_version,
value_type * old_ptr )
inlinenoexcept

Add an old copy.

This function will manage old copies. It will keep a list of copies that are still being used, and destroy and deallocate old copies that are no longer being used.

Parameters
old_versionThe version when the pointer was exchanged.
old_ptrThe pointer that was exchanged, may be a nullptr.

◆ capacity()

template<typename T , typename Allocator = std::allocator<T>>
size_t v1::rcu< T, Allocator >::capacity ( ) const
inlinenoexcept

Number of object that are currently allocated.

◆ copy()

template<typename T , typename Allocator = std::allocator<T>>
value_type * v1::rcu< T, Allocator >::copy ( ) const
inlinenoexcept

Create a copy of the value.

◆ emplace()

template<typename T , typename Allocator = std::allocator<T>>
template<typename... Args>
void v1::rcu< T, Allocator >::emplace ( Args &&... args)
inlinenoexcept

Emplace a new value.

This function will allocate and construct a new value, then replace the current value.

This function will also destroy and deallocate old values when no other threads are reading them.

Parameters
argsThe arguments passed to the constructor of the value.

◆ exchange()

template<typename T , typename Allocator = std::allocator<T>>
value_type * v1::rcu< T, Allocator >::exchange ( value_type * ptr)
inlinenoexcept

Exchange the rcu-pointers.

Note
This function should be called while holding the write-lock.
Parameters
ptrThe new pointer value, may be nullptr.
Returns
The old pointer value, may be nullptr.

◆ get()

template<typename T , typename Allocator = std::allocator<T>>
value_type const * v1::rcu< T, Allocator >::get ( )
inlinenoexcept

get the rcu-pointer.

◆ read_lock()

template<typename T , typename Allocator = std::allocator<T>>
void v1::rcu< T, Allocator >::read_lock ( )
inlinenoexcept

Lock the rcu pointer for reading.

◆ read_unlock()

template<typename T , typename Allocator = std::allocator<T>>
void v1::rcu< T, Allocator >::read_unlock ( )
inlinenoexcept

Unlock the rcu pointer for reading.

◆ unsafe_get()

template<typename T , typename Allocator = std::allocator<T>>
value_type const * v1::rcu< T, Allocator >::unsafe_get ( )
inlinenoexcept

Derefence the rcu-pointer.

Note
This function is unsafe you must follow the rules in https://github.com/torvalds/linux/blob/master/Documentation/RCU/rcu_dereference.rst

◆ version()

template<typename T , typename Allocator = std::allocator<T>>
uint64_t v1::rcu< T, Allocator >::version ( ) const
inlinenoexcept

The version of the lock.

The version is used to pass to add_old_copy(), it should be used while holding a write-lock.

◆ write_lock()

template<typename T , typename Allocator = std::allocator<T>>
void v1::rcu< T, Allocator >::write_lock ( )
inlinenoexcept

Lock the rcu pointer for writing.

◆ write_unlock()

template<typename T , typename Allocator = std::allocator<T>>
void v1::rcu< T, Allocator >::write_unlock ( )
inlinenoexcept

Unlock the rcu pointer for writing.


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