xenium
Public Member Functions | List of all members
xenium::left_right< T > Struct Template Reference

Generic implementation of the LeftRight algorithm proposed by Ramalhete and Correia [RC15]. More...

#include <left_right.hpp>

Public Member Functions

 left_right (T source)
 Initialize the two underlying T instances with the specified source. More...
 
 left_right (T left, T right)
 Initializes the two underlying instances withe the specified sources. More...
 
 left_right ()=default
 Default constructs both underlying instances.
 
template<typename Func >
auto read (Func &&func) const
 Performs a read operation on the active instance using the specified functor. More...
 
template<typename Func >
void update (Func &&func)
 Performs an update operation on both underlying instances using the specified functor. More...
 

Detailed Description

template<typename T>
struct xenium::left_right< T >

Generic implementation of the LeftRight algorithm proposed by Ramalhete and Correia [RC15].

The LeftRight algorithm provides the following advantages when compared to a read-write-lock:

This is comes at the cost of a duplication of the underlying data structure, which also means that update operations have to be applied to both instances.

Template Parameters
T

Constructor & Destructor Documentation

◆ left_right() [1/2]

template<typename T >
xenium::left_right< T >::left_right ( source)
inlineexplicit

Initialize the two underlying T instances with the specified source.

The first instance is copy-constructed while the second one is move-constructed.

Parameters
sourcethe source used to initialize the two underlying instances.

◆ left_right() [2/2]

template<typename T >
xenium::left_right< T >::left_right ( left,
right 
)
inline

Initializes the two underlying instances withe the specified sources.

Both instances are move-constructed from the specified sources.

Parameters
leftthe source to initialize the left instance
rightthe source to initialize the right instance

Member Function Documentation

◆ read()

template<typename T >
template<typename Func >
auto xenium::left_right< T >::read ( Func &&  func) const
inline

Performs a read operation on the active instance using the specified functor.

The functor func is called for the currently active instance. The instance is passed to the functor as a const reference.

This method simply returns the result of the call to func, i.e., the return type of this method corresponds to the return type of the func;

Template Parameters
Func
Parameters
func
Returns
the value returned by the call to func

◆ update()

template<typename T >
template<typename Func >
void xenium::left_right< T >::update ( Func &&  func)
inline

Performs an update operation on both underlying instances using the specified functor.

The functor func is called twice - once for each underlying instance. The instance to be updated is passed as a non-const reference to func.

Template Parameters
Func
Parameters
func