userver: rcu::WritablePtr< T, RcuTraits > Class Template Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
rcu::WritablePtr< T, RcuTraits > Class Template Reference

#include <userver/rcu/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* () &&
 

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 206 of file rcu.hpp.

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 209 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 218 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 227 of file rcu.hpp.

◆ ~WritablePtr()

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

Definition at line 234 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 243 of file rcu.hpp.

◆ Get() [1/2]

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

Definition at line 252 of file rcu.hpp.

◆ Get() [2/2]

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

Definition at line 257 of file rcu.hpp.

◆ operator*() [1/2]

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

Definition at line 262 of file rcu.hpp.

◆ operator*() [2/2]

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

Definition at line 263 of file rcu.hpp.

◆ operator->() [1/2]

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

Definition at line 259 of file rcu.hpp.

◆ operator->() [2/2]

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

Definition at line 260 of file rcu.hpp.


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