Click
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
unprotected_rcu_singlewriter< T, N > Class Template Reference

#include <multithread.hh>

Inheritance diagram for unprotected_rcu_singlewriter< T, N >:
unprotected_rcu< T, N >

Public Member Functions

 unprotected_rcu_singlewriter (T v)
 
void initialize (T v)
 
const T & read_begin ()
 
void read_end ()
 
const T & read () const
 
const T operator* () const
 
const T * operator-> () const
 
T & write_begin ()
 
void write_commit ()
 
void write_abort ()
 
const T & read_begin (int)
 
void read_end (int)
 

Protected Attributes

T storage [N]
 
volatile int rcu_current
 

Detailed Description

template<typename T, int N>
class unprotected_rcu_singlewriter< T, N >

unprotected_rcu_singlewriter implements a very simple SINGLE writer, multiple-reader rcu.

rcu allows to do a kind of atomic write with any structure. A temp copy is made for the writer, and when the writer has finished his write, he commits the change by changing the pointer for all subsequent readers.

Unlike usual RCU implementation, this one does not need lock for readers, however memory will be corrupted if N subsequent writes happens while a reader is obtaining a reference. If N cannot be asserted in your use-case, this structure is not for you. Hence, the unprotected in the name to attract attention to this fact.

This works by having a ring of N elements. The writer updates the next element of the ring, and when it has finished, it updates the current ring index to the next element. For fast wrap-up computing, N must be a power of 2 and at least 2.

Using a ring allows for getting rid of atomic reference count, but introduces the N problem.

For this to work, the template class must be able to copy itself with "=", eg : T b; b.do_something(); T a = b; This is true for primitive, but you may need to implement operator= for class

Usage : unprotected_rcu_singlewriter<my_struct,2> rcu_struct; reader : click_chatter("Member is %d.", rcu_struct.read().member); click_chatter("Member is %d.", rcu_struct->member); //Same, more convenient writer : my_struct &tmp_write = rcu_struct->write_begin(); tmp_write->member++; rcu_struct->write_commit();


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