Jack2 1.9.6
|
A class to handle several states in a lock-free manner. More...
#include <JackAtomicArrayState.h>
Public Member Functions | |
T * | ReadCurrentState () |
Returns the current state : only valid in the RT reader thread. | |
UInt16 | GetCurrentIndex () |
Returns the current switch counter. | |
T * | TrySwitchState (int state) |
Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) | |
T * | TrySwitchState (int state, bool *result) |
Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) | |
T * | WriteNextStateStart (int state) |
Start write operation : setup and returns the next state to update, check for recursive write calls. | |
T * | WriteNextStateStart (int state, bool *result) |
void | WriteNextStateStop (int state) |
Stop write operation : make the next state ready to be used by the RT thread. | |
Protected Member Functions | |
UInt32 | WriteNextStateStartAux (int state, bool *result) |
void | WriteNextStateStopAux (int state) |
Protected Attributes | |
T | fState [3] |
volatile AtomicArrayCounter | fCounter |
A class to handle several states in a lock-free manner.
Requirement:
The TrySwitchState operation returns a "current" state (either the same if switch fails or the new one, one can know if the switch has succeeded)
Different pending states can be written independantly and concurrently.
GetCurrentIndex() *must* return an increasing value to be able to check reading current state coherency
The fCounter is an array of indexes to access the current and 3 different "pending" states.
WriteNextStateStart(int index) must return a valid state to be written into, and must invalidate state "index" ==> cur state switch. WriteNextStateStop(int index) makes the "index" state become "switchable" with the current state. TrySwitchState(int index) must detect that pending state is a new state, and does the switch ReadCurrentState() must return the state GetCurrentIndex() must return an index increased each new switch. WriteNextStateStart(int index1) and WriteNextStateStart(int index2) can be interleaved
[switch counter][index state][index state][cur index]
Definition at line 113 of file JackAtomicArrayState.h.