Loading...
Searching...
No Matches
bit_pool.h File Reference

Bit pool data structure. More...

Functions

uint32_t spdk_bit_pool_capacity (const struct spdk_bit_pool *pool)
 Return the number of bits that a bit pool is currently sized to hold.
 
struct spdk_bit_pool * spdk_bit_pool_create (uint32_t num_bits)
 Create a bit pool.
 
struct spdk_bit_pool * spdk_bit_pool_create_from_array (struct spdk_bit_array *array)
 Create a bit pool from an existing spdk_bit_array.
 
void spdk_bit_pool_free (struct spdk_bit_pool **pool)
 Free a bit pool and set the pointer to NULL.
 
int spdk_bit_pool_resize (struct spdk_bit_pool **pool, uint32_t num_bits)
 Create or resize a bit pool.
 
bool spdk_bit_pool_is_allocated (const struct spdk_bit_pool *pool, uint32_t bit_index)
 Return whether the specified bit has been allocated from the bit pool.
 
uint32_t spdk_bit_pool_allocate_bit (struct spdk_bit_pool *pool)
 Allocate a bit from the bit pool.
 
void spdk_bit_pool_free_bit (struct spdk_bit_pool *pool, uint32_t bit_index)
 Free a bit back to the bit pool.
 
uint32_t spdk_bit_pool_count_allocated (const struct spdk_bit_pool *pool)
 Count the number of bits allocated from the pool.
 
uint32_t spdk_bit_pool_count_free (const struct spdk_bit_pool *pool)
 Count the number of free bits in the pool.
 
void spdk_bit_pool_store_mask (const struct spdk_bit_pool *pool, void *mask)
 Store bitmask from bit pool.
 
void spdk_bit_pool_load_mask (struct spdk_bit_pool *pool, const void *mask)
 Load bitmask to bit pool.
 
void spdk_bit_pool_free_all_bits (struct spdk_bit_pool *pool)
 Free all bits back into the bit pool.
 

Detailed Description

Bit pool data structure.

Function Documentation

◆ spdk_bit_pool_allocate_bit()

uint32_t spdk_bit_pool_allocate_bit ( struct spdk_bit_pool * pool)

Allocate a bit from the bit pool.

Parameters
poolBit pool to allocate a bit from
Returns
index of the allocated bit, UINT32_MAX if no free bits exist

◆ spdk_bit_pool_capacity()

uint32_t spdk_bit_pool_capacity ( const struct spdk_bit_pool * pool)

Return the number of bits that a bit pool is currently sized to hold.

Parameters
poolBit pool to query.
Returns
the number of bits.

◆ spdk_bit_pool_count_allocated()

uint32_t spdk_bit_pool_count_allocated ( const struct spdk_bit_pool * pool)

Count the number of bits allocated from the pool.

Parameters
poolThe bit pool to count.
Returns
the number of bits allocated from the pool.

◆ spdk_bit_pool_count_free()

uint32_t spdk_bit_pool_count_free ( const struct spdk_bit_pool * pool)

Count the number of free bits in the pool.

Parameters
poolThe bit pool to count.
Returns
the number of free bits in the pool.

◆ spdk_bit_pool_create()

struct spdk_bit_pool * spdk_bit_pool_create ( uint32_t num_bits)

Create a bit pool.

All bits in the pool will be available for allocation.

Parameters
num_bitsNumber of bits that the bit pool is sized to hold.
Returns
a pointer to the new bit pool.

◆ spdk_bit_pool_create_from_array()

struct spdk_bit_pool * spdk_bit_pool_create_from_array ( struct spdk_bit_array * array)

Create a bit pool from an existing spdk_bit_array.

The starting state of the bit pool will be specified by the state of the specified spdk_bit_array.

The new spdk_bit_pool will consume the spdk_bit_array and assumes responsibility for freeing it. The caller should not use the spdk_bit_array after this function returns.

Parameters
arrayspdk_bit_array representing the starting state of the new bit pool.
Returns
a pointer to the new bit pool, NULL if one could not be created (in which case the caller maintains responsibility for the spdk_bit_array)

◆ spdk_bit_pool_free()

void spdk_bit_pool_free ( struct spdk_bit_pool ** pool)

Free a bit pool and set the pointer to NULL.

Parameters
poolBit pool to free.

◆ spdk_bit_pool_free_all_bits()

void spdk_bit_pool_free_all_bits ( struct spdk_bit_pool * pool)

Free all bits back into the bit pool.

Parameters
poolBit pool.

◆ spdk_bit_pool_free_bit()

void spdk_bit_pool_free_bit ( struct spdk_bit_pool * pool,
uint32_t bit_index )

Free a bit back to the bit pool.

Callers must not try to free a bit that has not been allocated, otherwise the pool may become corrupted without notification. Freeing a bit that has not been allocated will result in an assert in debug builds.

Parameters
poolBit pool to place the freed bit
bit_indexThe index of a bit to free.

◆ spdk_bit_pool_is_allocated()

bool spdk_bit_pool_is_allocated ( const struct spdk_bit_pool * pool,
uint32_t bit_index )

Return whether the specified bit has been allocated from the bit pool.

If bit_index is beyond the end of the current size of the bit pool, this function will return false (i.e. bits beyond the end of the pool cannot be allocated).

Parameters
poolBit pool to query.
bit_indexThe index of a bit to query.
Returns
true if the bit has been allocated, false otherwise

◆ spdk_bit_pool_load_mask()

void spdk_bit_pool_load_mask ( struct spdk_bit_pool * pool,
const void * mask )

Load bitmask to bit pool.

Parameters
poolBit pool.
maskSource mask. Mask and bit array pool must be equal.

◆ spdk_bit_pool_resize()

int spdk_bit_pool_resize ( struct spdk_bit_pool ** pool,
uint32_t num_bits )

Create or resize a bit pool.

To create a new bit pool, pass a pointer to a spdk_bit_pool pointer that is NULL.

The bit pool will be sized to hold at least num_bits.

If num_bits is larger than the previous size of the bit pool, the new bits will all be available for future allocations.

Parameters
poolBit pool to create/resize.
num_bitsNumber of bits that the bit pool is sized to hold.
Returns
0 on success, negative errno on failure.

◆ spdk_bit_pool_store_mask()

void spdk_bit_pool_store_mask ( const struct spdk_bit_pool * pool,
void * mask )

Store bitmask from bit pool.

Parameters
poolBit pool.
maskDestination mask. Mask and bit array pool must be equal.