Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ShadowedStoredBitSet Class Reference
Inheritance diagram for ShadowedStoredBitSet:
StoredBitSet Atomic EEPROMStoredBitSet< HW >

Public Member Functions

StoredBitSetset_bit (unsigned offset, bool value) override
 Sets an individual bit to a specific value.
 
bool get_bit (unsigned offset) override
 Retrieves an individual bit.
 
StoredBitSetset_multi (unsigned offset, unsigned size, unsigned value) override
 Sets a block of consecutive bits.
 
unsigned get_multi (unsigned offset, unsigned size) override
 Returns a block of consecutive bits as an integer value.
 
unsigned size () override
 
void lock_and_flush () override
 Grabs a lock and writes the current values to persistent storage.
 
- Public Member Functions inherited from StoredBitSet
virtual void flush ()=0
 Writes the current values to persistent storage.
 

Protected Types

typedef uint8_t cell_offs_t
 Type indexing cells. Must be an unsigned type.
 
typedef unsigned bit_offs_t
 Type indexing all bits.
 

Protected Member Functions

 ShadowedStoredBitSet (unsigned size, uint8_t granularity)
 
cell_offs_t next_dirty ()
 
void clear_dirty (cell_offs_t cell)
 Clears the dirty bit for a given cell.
 
bool is_dirty (cell_offs_t cell)
 
cell_offs_t num_cells ()
 
- Protected Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Static Protected Attributes

static constexpr cell_offs_t NO_CELL = static_cast<cell_offs_t>(-1)
 

Private Member Functions

unsigned dirty_size_uint32 ()
 
void update_dirty_bounds (cell_offs_t d)
 updates lowestDirty_ and highestDirty_ for a given cell.
 

Private Attributes

const unsigned size_
 Total number of bits.
 
const uint8_t granularity_
 How many bits per cell.
 
cell_offs_t lowestDirty_ {NO_CELL}
 Helper values for iterating over the dirty bits.
 
cell_offs_t highestDirty_ {0}
 
uint32_t * shadow_
 Data of the actual bits. length is size_ / 32 rounded up.
 
uint32_t * dirty_
 Bit set telling whether the individual cells are dirty or not (i.e.
 

Detailed Description

Definition at line 91 of file StoredBitSet.hxx.

Member Typedef Documentation

◆ bit_offs_t

typedef unsigned ShadowedStoredBitSet::bit_offs_t
protected

Type indexing all bits.

Definition at line 217 of file StoredBitSet.hxx.

◆ cell_offs_t

typedef uint8_t ShadowedStoredBitSet::cell_offs_t
protected

Type indexing cells. Must be an unsigned type.

Definition at line 215 of file StoredBitSet.hxx.

Constructor & Destructor Documentation

◆ ShadowedStoredBitSet()

ShadowedStoredBitSet::ShadowedStoredBitSet ( unsigned  size,
uint8_t  granularity 
)
inlineprotected
Parameters
sizeis the total number of bits we store.
granularitytells how many bits fit into a single cell. The base class will then keep track of dirty cells.

Definition at line 198 of file StoredBitSet.hxx.

◆ ~ShadowedStoredBitSet()

ShadowedStoredBitSet::~ShadowedStoredBitSet ( )
inlineprotected

Definition at line 209 of file StoredBitSet.hxx.

Member Function Documentation

◆ clear_dirty()

void ShadowedStoredBitSet::clear_dirty ( cell_offs_t  cell)
inlineprotected

Clears the dirty bit for a given cell.

Parameters
cellis the number of the cell, 0..num_cells()-1.

Definition at line 254 of file StoredBitSet.hxx.

◆ dirty_size_uint32()

unsigned ShadowedStoredBitSet::dirty_size_uint32 ( )
inlineprivate
Returns
how many uint32 are there in the dirty_ array.

Definition at line 276 of file StoredBitSet.hxx.

◆ get_bit()

bool ShadowedStoredBitSet::get_bit ( unsigned  offset)
inlineoverridevirtual

Retrieves an individual bit.

Parameters
offsetis the bit number to retrieve.
Returns
the last set bit value.

Implements StoredBitSet.

Definition at line 113 of file StoredBitSet.hxx.

◆ get_multi()

unsigned ShadowedStoredBitSet::get_multi ( unsigned  offset,
unsigned  size 
)
inlineoverridevirtual

Returns a block of consecutive bits as an integer value.

Parameters
offsetis the number of the first bit to retrieve.
sizeis the number of bits to retrieve.
Returns
the unsigned value that the last set bits represent, with LSB-first (bit 0 will be from offset; bit 1 will be from offset + 1, etc.)

Implements StoredBitSet.

Definition at line 170 of file StoredBitSet.hxx.

◆ is_dirty()

bool ShadowedStoredBitSet::is_dirty ( cell_offs_t  cell)
inlineprotected
Returns
true if the given cell is dirty.
Parameters
cellis the number of the cell, 0..num_cells()-1.

Definition at line 264 of file StoredBitSet.hxx.

◆ lock_and_flush()

void ShadowedStoredBitSet::lock_and_flush ( )
inlineoverridevirtual

Grabs a lock and writes the current values to persistent storage.

Implements StoredBitSet.

Definition at line 189 of file StoredBitSet.hxx.

◆ next_dirty()

cell_offs_t ShadowedStoredBitSet::next_dirty ( )
inlineprotected
Returns
the cell number of the next dirty cell, or NO_CELL if nothing is dirty anymore.

Definition at line 223 of file StoredBitSet.hxx.

◆ num_cells()

cell_offs_t ShadowedStoredBitSet::num_cells ( )
inlineprotected
Returns
how many cells we have, each with granularity_ bits stored.

Definition at line 270 of file StoredBitSet.hxx.

◆ set_bit()

StoredBitSet & ShadowedStoredBitSet::set_bit ( unsigned  offset,
bool  value 
)
inlineoverridevirtual

Sets an individual bit to a specific value.

This call is thread-safe.

Parameters
offsetis the bit number to set.
valueis the new value for that bit.
Returns
*this.

Implements StoredBitSet.

Definition at line 94 of file StoredBitSet.hxx.

◆ set_multi()

StoredBitSet & ShadowedStoredBitSet::set_multi ( unsigned  offset,
unsigned  size,
unsigned  value 
)
inlineoverridevirtual

Sets a block of consecutive bits.

This call is thread-safe.

Parameters
offsetis the number of the first bit to set.
sizeis the number of bits to set.
valuecontains the data to write, LSB (bit 0) goes to "offset", bit 1 goes to offset + 1, etc.; bits at and above size are checked to be zero.
Returns
*this.

Implements StoredBitSet.

Definition at line 118 of file StoredBitSet.hxx.

◆ size()

unsigned ShadowedStoredBitSet::size ( )
inlineoverridevirtual
Returns
the number of bits in the storage. Valid offsets are 0..size()-1.

Implements StoredBitSet.

Definition at line 185 of file StoredBitSet.hxx.

◆ update_dirty_bounds()

void ShadowedStoredBitSet::update_dirty_bounds ( cell_offs_t  d)
inlineprivate

updates lowestDirty_ and highestDirty_ for a given cell.

Parameters
dcell offset to set dirty

Definition at line 282 of file StoredBitSet.hxx.

Member Data Documentation

◆ dirty_

uint32_t* ShadowedStoredBitSet::dirty_
private

Bit set telling whether the individual cells are dirty or not (i.e.

need to be flushed). LSB-first in the individual bits, i.e. bit 1 of entry 2 means that the cell numbered (2*32 + 1) is dirty.

Definition at line 313 of file StoredBitSet.hxx.

◆ granularity_

const uint8_t ShadowedStoredBitSet::granularity_
private

How many bits per cell.

Definition at line 303 of file StoredBitSet.hxx.

◆ highestDirty_

cell_offs_t ShadowedStoredBitSet::highestDirty_ {0}
private

Definition at line 306 of file StoredBitSet.hxx.

◆ lowestDirty_

cell_offs_t ShadowedStoredBitSet::lowestDirty_ {NO_CELL}
private

Helper values for iterating over the dirty bits.

Definition at line 305 of file StoredBitSet.hxx.

◆ NO_CELL

constexpr cell_offs_t ShadowedStoredBitSet::NO_CELL = static_cast<cell_offs_t>(-1)
staticconstexprprotected

Definition at line 219 of file StoredBitSet.hxx.

◆ shadow_

uint32_t* ShadowedStoredBitSet::shadow_
private

Data of the actual bits. length is size_ / 32 rounded up.

Definition at line 309 of file StoredBitSet.hxx.

◆ size_

const unsigned ShadowedStoredBitSet::size_
private

Total number of bits.

Definition at line 301 of file StoredBitSet.hxx.


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