Bitcoin ABC 0.30.5
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 b 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 47 of file cuckoocache.h.

Constructor & Destructor Documentation

◆ bit_packed_atomic_flags() [1/2]

CuckooCache::bit_packed_atomic_flags::bit_packed_atomic_flags ( )
delete

No default constructor, as there must be some size.

◆ bit_packed_atomic_flags() [2/2]

CuckooCache::bit_packed_atomic_flags::bit_packed_atomic_flags ( uint32_t  size)
inlineexplicit

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 65 of file cuckoocache.h.

Member Function Documentation

◆ bit_is_set()

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
true if the bit at index s was set, false otherwise

Definition at line 118 of file cuckoocache.h.

Here is the caller graph for this function:

◆ bit_set()

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 96 of file cuckoocache.h.

Here is the caller graph for this function:

◆ bit_unset()

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 107 of file cuckoocache.h.

Here is the caller graph for this function:

◆ setup()

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 b 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 84 of file cuckoocache.h.

Here is the caller graph for this function:

Member Data Documentation

◆ mem

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

Definition at line 48 of file cuckoocache.h.


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