RAVENNAKIT
Loading...
Searching...
No Matches
rav::RealtimeSharedObject< T > Class Template Reference

This class provides a real-time safe way to share objects among a single reader. More...

#include <realtime_shared_object.hpp>

Classes

class  RealtimeAccessGuard
 A guard object provides access to the value. More...

Public Member Functions

 RealtimeSharedObject ()=default
 Default constructor.
 RealtimeSharedObject (T initial_value)
 ~RealtimeSharedObject ()
 RealtimeSharedObject (const RealtimeSharedObject &)=delete
RealtimeSharedObject & operator= (const RealtimeSharedObject &)=delete
 RealtimeSharedObject (RealtimeSharedObject &&)=delete
RealtimeSharedObject & operator= (RealtimeSharedObject &&)=delete
RealtimeAccessGuard access_realtime ()
std::optional< T > update (T value)
 Swaps current value by given value by placing the new value into the active slot, and then swapping the pointer for the realtime thread.
bool reset ()
 Resets the object to contain a new, default constructed object.

Static Public Attributes

static constexpr size_t k_loop_upper_bound = 1'000'000
 The max number of tries before giving up (preventing runaway code).
static constexpr uint32_t k_yield_threshold = 10
 The number of iterations after which a function will start yielding.
static constexpr uint32_t k_sleep_threshold = 10'000
 The number of iterations after which a function will start sleeping.

Detailed Description

template<class T>
class rav::RealtimeSharedObject< T >

This class provides a real-time safe way to share objects among a single reader.

The writer side is protected by a mutex. Internally a double buffer and CAS loop is used to update the value in a thread-safe manner.

Template Parameters
TThe type of the object to share.

Definition at line 41 of file realtime_shared_object.hpp.

Constructor & Destructor Documentation

◆ RealtimeSharedObject() [1/4]

template<class T>
rav::RealtimeSharedObject< T >::RealtimeSharedObject ( )
default

Default constructor.

◆ RealtimeSharedObject() [2/4]

template<class T>
rav::RealtimeSharedObject< T >::RealtimeSharedObject ( T initial_value)
inlineexplicit
Parameters
initial_valueInitial value to set.

Definition at line 137 of file realtime_shared_object.hpp.

◆ ~RealtimeSharedObject()

template<class T>
rav::RealtimeSharedObject< T >::~RealtimeSharedObject ( )
inline

Definition at line 139 of file realtime_shared_object.hpp.

◆ RealtimeSharedObject() [3/4]

template<class T>
rav::RealtimeSharedObject< T >::RealtimeSharedObject ( const RealtimeSharedObject< T > & )
delete

◆ RealtimeSharedObject() [4/4]

template<class T>
rav::RealtimeSharedObject< T >::RealtimeSharedObject ( RealtimeSharedObject< T > && )
delete

Member Function Documentation

◆ access_realtime()

template<class T>
RealtimeAccessGuard rav::RealtimeSharedObject< T >::access_realtime ( )
inlinenodiscard
Returns
Get a lock for realtime access to the current value. During the lifetime of this lock (or until reset is called) no updates can be made to the value. Real-time safe: yes, wait-free Thread safe: no.

Definition at line 154 of file realtime_shared_object.hpp.

◆ operator=() [1/2]

template<class T>
RealtimeSharedObject & rav::RealtimeSharedObject< T >::operator= ( const RealtimeSharedObject< T > & )
delete

◆ operator=() [2/2]

template<class T>
RealtimeSharedObject & rav::RealtimeSharedObject< T >::operator= ( RealtimeSharedObject< T > && )
delete

◆ reset()

template<class T>
bool rav::RealtimeSharedObject< T >::reset ( )
inlinenodiscard

Resets the object to contain a new, default constructed object.

Returns
True if resetting succeeded, or false if not.

Definition at line 192 of file realtime_shared_object.hpp.

◆ update()

template<class T>
std::optional< T > rav::RealtimeSharedObject< T >::update ( T value)
inlinenodiscard

Swaps current value by given value by placing the new value into the active slot, and then swapping the pointer for the realtime thread.

Parameters
valueThe new value to share with the realtime thread.
Returns
An optional containing the previous value, or nullopt when the loop upper bound is reached.

Definition at line 164 of file realtime_shared_object.hpp.

Member Data Documentation

◆ k_loop_upper_bound

template<class T>
size_t rav::RealtimeSharedObject< T >::k_loop_upper_bound = 1'000'000
staticconstexpr

The max number of tries before giving up (preventing runaway code).

Definition at line 44 of file realtime_shared_object.hpp.

◆ k_sleep_threshold

template<class T>
uint32_t rav::RealtimeSharedObject< T >::k_sleep_threshold = 10'000
staticconstexpr

The number of iterations after which a function will start sleeping.

Definition at line 50 of file realtime_shared_object.hpp.

◆ k_yield_threshold

template<class T>
uint32_t rav::RealtimeSharedObject< T >::k_yield_threshold = 10
staticconstexpr

The number of iterations after which a function will start yielding.

Definition at line 47 of file realtime_shared_object.hpp.


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