userver: rcu::WritablePtr< T, RcuTraits > Class Template Reference
Loading...
Searching...
No Matches
rcu::WritablePtr< T, RcuTraits > Class Template Reference

#include <userver/rcu/rcu.hpp>

Detailed Description

template<typename T, typename RcuTraits>
class rcu::WritablePtr< T, RcuTraits >

Smart pointer for rcu::Variable<T> for changing RCU value. It stores a reference to a to-be-changed value and allows one to mutate the value (e.g. add items to std::unordered_map). Changed value is not visible to readers until explicit store by Commit. Only a single writer may own a WritablePtr associated with the same Variable, so WritablePtr creates a critical section. This critical section doesn't affect readers, so a slow writer doesn't block readers.

Note
you may not pass WritablePtr between coroutines as it owns engine::Mutex, which must be unlocked in the same coroutine that was used to lock the mutex.

Definition at line 208 of file rcu.hpp.

Public Member Functions

 WritablePtr (Variable< T, RcuTraits > &var)
 For internal use only. Use var.StartWrite() instead.
 
template<typename... Args>
 WritablePtr (Variable< T, RcuTraits > &var, std::in_place_t, Args &&... initial_value_args)
 For internal use only. Use var.Emplace(args...) instead.
 
 WritablePtr (WritablePtr< T, RcuTraits > &&other) noexcept
 
void Commit ()
 
T * Get () &
 
T * Get () &&
 
T * operator-> () &
 
T * operator-> () &&
 
T & operator* () &
 
T & operator* () &&
 

Constructor & Destructor Documentation

◆ WritablePtr() [1/3]

template<typename T , typename RcuTraits >
rcu::WritablePtr< T, RcuTraits >::WritablePtr ( Variable< T, RcuTraits > & var)
inlineexplicit

For internal use only. Use var.StartWrite() instead.

Definition at line 211 of file rcu.hpp.

◆ WritablePtr() [2/3]

template<typename T , typename RcuTraits >
template<typename... Args>
rcu::WritablePtr< T, RcuTraits >::WritablePtr ( Variable< T, RcuTraits > & var,
std::in_place_t ,
Args &&... initial_value_args )
inline

For internal use only. Use var.Emplace(args...) instead.

Definition at line 220 of file rcu.hpp.

◆ WritablePtr() [3/3]

template<typename T , typename RcuTraits >
rcu::WritablePtr< T, RcuTraits >::WritablePtr ( WritablePtr< T, RcuTraits > && other)
inlinenoexcept

Definition at line 229 of file rcu.hpp.

◆ ~WritablePtr()

template<typename T , typename RcuTraits >
rcu::WritablePtr< T, RcuTraits >::~WritablePtr ( )
inline

Definition at line 236 of file rcu.hpp.

Member Function Documentation

◆ Commit()

template<typename T , typename RcuTraits >
void rcu::WritablePtr< T, RcuTraits >::Commit ( )
inline

Store the changed value in Variable. After Commit() the value becomes visible to new readers (IOW, Variable::Read() returns ReadablePtr referencing the stored value, not an old value).

Definition at line 245 of file rcu.hpp.

◆ Get() [1/2]

template<typename T , typename RcuTraits >
T * rcu::WritablePtr< T, RcuTraits >::Get ( ) &
inline

Definition at line 254 of file rcu.hpp.

◆ Get() [2/2]

template<typename T , typename RcuTraits >
T * rcu::WritablePtr< T, RcuTraits >::Get ( ) &&
inline

Definition at line 259 of file rcu.hpp.

◆ operator*() [1/2]

template<typename T , typename RcuTraits >
T & rcu::WritablePtr< T, RcuTraits >::operator* ( ) &
inline

Definition at line 264 of file rcu.hpp.

◆ operator*() [2/2]

template<typename T , typename RcuTraits >
T & rcu::WritablePtr< T, RcuTraits >::operator* ( ) &&
inline

Definition at line 265 of file rcu.hpp.

◆ operator->() [1/2]

template<typename T , typename RcuTraits >
T * rcu::WritablePtr< T, RcuTraits >::operator-> ( ) &
inline

Definition at line 261 of file rcu.hpp.

◆ operator->() [2/2]

template<typename T , typename RcuTraits >
T * rcu::WritablePtr< T, RcuTraits >::operator-> ( ) &&
inline

Definition at line 262 of file rcu.hpp.


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