#include <stddef.h>
#include <stdint.h>
#include <kernel.h>
Go to the source code of this file.
|
int | sys_bitarray_set_bit (sys_bitarray_t *bitarray, size_t bit) |
|
int | sys_bitarray_clear_bit (sys_bitarray_t *bitarray, size_t bit) |
|
int | sys_bitarray_test_bit (sys_bitarray_t *bitarray, size_t bit, int *val) |
|
int | sys_bitarray_test_and_set_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) |
|
int | sys_bitarray_test_and_clear_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) |
|
int | sys_bitarray_alloc (sys_bitarray_t *bitarray, size_t num_bits, size_t *offset) |
|
int | sys_bitarray_free (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
|
bool | sys_bitarray_is_region_set (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
|
bool | sys_bitarray_is_region_cleared (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
|
int | sys_bitarray_set_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
|
int | sys_bitarray_clear_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
|
◆ SYS_BITARRAY_DEFINE
#define SYS_BITARRAY_DEFINE |
( |
|
name, |
|
|
|
total_bits |
|
) |
| |
Value:
[(((total_bits + 8 - 1) / 8) +
sizeof(
uint32_t) - 1) \
sys_bitarray_t name = { \
.num_bits = total_bits, \
.num_bundles = (((total_bits + 8 - 1) / 8) \
.bundles = _sys_bitarray_bundles_##name, \
}
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Create a bitarray object.
- Parameters
-
name | Name of the bitarray object. |
total_bits | Total number of bits in this bitarray object. |
◆ sys_bitarray_t
◆ sys_bitarray_alloc()
int sys_bitarray_alloc |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t * |
offset |
|
) |
| |
Allocate bits in a bit array
This finds a number of bits (num_bits
) in a contiguous of previosly unallocated region. If such a region exists, the bits are marked as allocated and the offset to the start of this region is returned via offset
.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | num_bits | Number of bits to allocate |
[out] | offset | Offset to the start of allocated region if successful |
- Return values
-
0 | Allocation successful |
-EINVAL | Invalid argument (e.g. allocating more bits than the bitarray has, trying to allocate 0 bits, etc.) |
-ENOSPC | No contiguous region big enough to accommodate the allocation |
◆ sys_bitarray_clear_bit()
Clear a bit in a bit array
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be cleared |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to clear exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_clear_region()
int sys_bitarray_clear_region |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t |
offset |
|
) |
| |
Clear all bits in a region.
This clears the number of bits (num_bits
) in region starting from offset
.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_free()
int sys_bitarray_free |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t |
offset |
|
) |
| |
Free bits in a bit array
This marks the number of bits (num_bits
) starting from offset
as no longer allocated.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to free |
offset | Starting bit position to free |
- Return values
-
0 | Free is successful |
-EINVAL | Invalid argument (e.g. try to free more bits than the bitarray has, trying to free 0 bits, etc.) |
-EFAULT | The bits in the indicated region are not all allocated. |
◆ sys_bitarray_is_region_cleared()
bool sys_bitarray_is_region_cleared |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t |
offset |
|
) |
| |
Test if bits in a region is all cleared.
This tests if the number of bits (num_bits
) in region starting from offset
are all cleared.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
true | All bits are cleared. |
false | Not all bits are cleared. |
◆ sys_bitarray_is_region_set()
bool sys_bitarray_is_region_set |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t |
offset |
|
) |
| |
Test if bits in a region is all set.
This tests if the number of bits (num_bits
) in region starting from offset
are all set.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
true | All bits are set. |
false | Not all bits are set. |
◆ sys_bitarray_set_bit()
Set a bit in a bit array
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be set |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_set_region()
int sys_bitarray_set_region |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
num_bits, |
|
|
size_t |
offset |
|
) |
| |
Set all bits in a region.
This sets the number of bits (num_bits
) in region starting from offset
.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_and_clear_bit()
int sys_bitarray_test_and_clear_bit |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
bit, |
|
|
int * |
prev_val |
|
) |
| |
Test the bit and clear it
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested and cleared |
[out] | prev_val | Previous value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_and_set_bit()
int sys_bitarray_test_and_set_bit |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
bit, |
|
|
int * |
prev_val |
|
) |
| |
Test the bit and set it
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested and set |
[out] | prev_val | Previous value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_bit()
int sys_bitarray_test_bit |
( |
sys_bitarray_t * |
bitarray, |
|
|
size_t |
bit, |
|
|
int * |
val |
|
) |
| |
Test whether a bit is set or not
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested |
[out] | val | The value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |