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. With regular mutex traits, the writer mutex serializes concurrent write transactions and is held until Commit or WritablePtr destruction. StartWrite acquires the mutex and then copies the latest committed value into the transaction. In-place write APIs acquire the mutex before constructing the internal replacement value. 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 324 of file rcu.hpp.

Public Member Functions

 WritablePtr (WritablePtr &&other) noexcept
void Commit ()
T * Get () &
T * Get () &&
T * operator-> () &
T * operator-> () &&
T & operator* () &
T & operator* () &&

Constructor & Destructor Documentation

◆ WritablePtr()

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

Definition at line 343 of file rcu.hpp.

◆ ~WritablePtr()

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

Definition at line 346 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 and release the writer mutex. 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 355 of file rcu.hpp.

◆ Get() [1/2]

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

Definition at line 361 of file rcu.hpp.

◆ Get() [2/2]

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

Definition at line 366 of file rcu.hpp.

◆ operator*() [1/2]

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

Definition at line 371 of file rcu.hpp.

◆ operator*() [2/2]

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

Definition at line 372 of file rcu.hpp.

◆ operator->() [1/2]

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

Definition at line 368 of file rcu.hpp.

◆ operator->() [2/2]

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

Definition at line 369 of file rcu.hpp.


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