Fabcoin Core  0.16.2
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
CuckooCache::bit_packed_atomic_flags Class Reference

bit_packed_atomic_flags implements a container for garbage collection flags that is only thread unsafe on calls to setup. More...

#include <cuckoocache.h>

Public Member Functions

 bit_packed_atomic_flags ()=delete
 No default constructor as there must be some size. More...
 
 bit_packed_atomic_flags (uint32_t size)
 bit_packed_atomic_flags constructor creates memory to sufficiently keep track of garbage collection information for size entries. More...
 
void setup (uint32_t b)
 setup marks all entries and ensures that bit_packed_atomic_flags can store at least size entries More...
 
void bit_set (uint32_t s)
 bit_set sets an entry as discardable. More...
 
void bit_unset (uint32_t s)
 bit_unset marks an entry as something that should not be overwritten More...
 
bool bit_is_set (uint32_t s) const
 bit_is_set queries the table for discardability at s More...
 

Private Attributes

std::unique_ptr< std::atomic< uint8_t >[]> mem
 

Detailed Description

bit_packed_atomic_flags implements a container for garbage collection flags that is only thread unsafe on calls to setup.

This class bit-packs collection flags for memory efficiency.

All operations are std::memory_order_relaxed so external mechanisms must ensure that writes and reads are properly synchronized.

On setup(n), all bits up to n are marked as collected.

Under the hood, because it is an 8-bit type, it makes sense to use a multiple of 8 for setup, but it will be safe if that is not the case as well.

Definition at line 42 of file cuckoocache.h.

Constructor & Destructor Documentation

CuckooCache::bit_packed_atomic_flags::bit_packed_atomic_flags ( )
delete

No default constructor as there must be some size.

CuckooCache::bit_packed_atomic_flags::bit_packed_atomic_flags ( uint32_t  size)
inline

bit_packed_atomic_flags constructor creates memory to sufficiently keep track of garbage collection information for size entries.

Parameters
sizethe number of elements to allocate space for
Postcondition
bit_set, bit_unset, and bit_is_set function properly forall x. x < size
All calls to bit_is_set (without subsequent bit_unset) will return true.

Definition at line 61 of file cuckoocache.h.

Member Function Documentation

bool CuckooCache::bit_packed_atomic_flags::bit_is_set ( uint32_t  s) const
inline

bit_is_set queries the table for discardability at s

Parameters
sthe index of the entry to read.
Returns
if the bit at index s was set.

Definition at line 113 of file cuckoocache.h.

Here is the caller graph for this function:

void CuckooCache::bit_packed_atomic_flags::bit_set ( uint32_t  s)
inline

bit_set sets an entry as discardable.

Parameters
sthe index of the entry to bit_set.
Postcondition
immediately subsequent call (assuming proper external memory ordering) to bit_is_set(s) == true.

Definition at line 92 of file cuckoocache.h.

Here is the caller graph for this function:

void CuckooCache::bit_packed_atomic_flags::bit_unset ( uint32_t  s)
inline

bit_unset marks an entry as something that should not be overwritten

Parameters
sthe index of the entry to bit_unset.
Postcondition
immediately subsequent call (assuming proper external memory ordering) to bit_is_set(s) == false.

Definition at line 103 of file cuckoocache.h.

Here is the caller graph for this function:

void CuckooCache::bit_packed_atomic_flags::setup ( uint32_t  b)
inline

setup marks all entries and ensures that bit_packed_atomic_flags can store at least size entries

Parameters
bthe number of elements to allocate space for
Postcondition
bit_set, bit_unset, and bit_is_set function properly forall x. x < b
All calls to bit_is_set (without subsequent bit_unset) will return true.

Definition at line 79 of file cuckoocache.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::unique_ptr<std::atomic<uint8_t>[]> CuckooCache::bit_packed_atomic_flags::mem
private

Definition at line 44 of file cuckoocache.h.


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