Jack2: Jack::JackAtomicArrayState< T > Class Template Reference

Jack2 1.9.12

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Jack::JackAtomicArrayState< T > Class Template Reference

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

## Detailed Description

### template<class T>
class Jack::JackAtomicArrayState< T >

A class to handle several states in a lock-free manner.

Requirement:

        - a "current" state
        - several possible "pending" state
        - an TrySwitchState(int state) operation to atomically switch a "pending" to the "current" state (the pending becomes the current).

        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)

        - a WriteNextStartState(int state) returns a "pending" state to be written into
        - a WriteNextStartStop(int state) make the written "pending" state become "switchable"

        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 114 of file JackAtomicArrayState.h.

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

- JackAtomicArrayState.h