Different modules often share a number of fundamental requirements and concepts. Picotm comes with a large number of data structures and functions for modules to re-use. This includes locks, tree maps, arrays, reference-counting and more. More...
Files | |
file | picotm-lib-array.h |
file | picotm-lib-ptr.h |
file | picotm-lib-ref.h |
file | picotm-lib-rwlock.h |
file | picotm-lib-rwstate.h |
Contains struct picotm_rwstate and helpers. | |
file | picotm-lib-shared-ref-obj.h |
Contains struct picotm_shared_ref16_obj and helper functions. | |
file | picotm-lib-shared-treemap.h |
Contains struct picotm_shared_treemap and helper functions. | |
file | picotm-lib-spinlock.h |
Contains struct picotm_spinlock and helper functions. | |
file | picotm-lib-tab.h |
file | picotm-lib-treemap.h |
Contains struct picotm_treemap and helpers. | |
Data Structures | |
struct | picotm_ref16 |
struct | picotm_rwlock |
A reader-writer lock. More... | |
struct | picotm_rwstate |
struct | picotm_shared_ref16 |
struct | picotm_shared_ref16_obj |
struct | picotm_shared_treemap |
Maps keys to values. More... | |
struct | picotm_spinlock |
Provides an operating-system-neutral, non-recursive spin-lock type. More... | |
struct | picotm_treemap |
Maps keys to values. More... | |
Macros | |
#define | picotm_arrayat(_array, _i) |
#define | picotm_arraybeg(_array) |
#define | picotm_arrayend(_array) |
#define | picotm_arrayfirst(_array) |
#define | picotm_arraylast(_array) |
#define | picotm_arraylen(_array) |
#define | picotm_containerof(ptr, type, member) |
#define | picotm_ref_count(self) |
#define | picotm_ref_down(self) |
#define | picotm_ref_init(self, count) |
#define | PICOTM_REF_INITIALIZER(__count) |
#define | picotm_ref_up(self) |
#define | PICOTM_RWLOCK_INITIALIZER |
Initializer macro for R/W state variables. | |
#define | PICOTM_RWSTATE_INITIALIZER |
Initializer macro for R/W state variables. | |
#define | PICOTM_SHARED_REF16_INITIALIZER(count) |
#define | PICOTM_SHARED_REF16_OBJ_INITIALIZER |
#define | PICOTM_SHARED_REF_INITIALIZER(__count) |
#define | picotm_sizeof_align(__type) |
Returns the number of size and alignment bytes of a given type. More... | |
#define | PICOTM_SPINLOCK_INITIALIZER |
Initializer macro for picotm spin locks. | |
Typedefs | |
typedef bool(* | picotm_shared_ref16_obj_condition_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
typedef void(* | picotm_shared_ref16_obj_final_ref_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
typedef void(* | picotm_shared_ref16_obj_first_ref_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
typedef uintptr_t(* | picotm_shared_treemap_value_create_function) (unsigned long long key, struct picotm_shared_treemap *treemap, struct picotm_error *error) |
typedef void(* | picotm_shared_treemap_value_destroy_function) (uintptr_t value, struct picotm_shared_treemap *treemap) |
typedef int(* | picotm_tab_compare_function) (const void *data0, const void *data1) |
typedef size_t(* | picotm_tabwalk_1_function) (void *data0, struct picotm_error *error) |
typedef size_t(* | picotm_tabwalk_2_function) (void *data0, void *data1, struct picotm_error *error) |
typedef size_t(* | picotm_tabwalk_3_function) (void *data0, void *data1, void *data2, struct picotm_error *error) |
typedef void(* | picotm_treemap_value_call_function) (uintptr_t value, unsigned long long key, struct picotm_treemap *treemap, void *data, struct picotm_error *error) |
typedef uintptr_t(* | picotm_treemap_value_create_function) (unsigned long long key, struct picotm_treemap *treemap, struct picotm_error *error) |
typedef void(* | picotm_treemap_value_destroy_function) (uintptr_t value, struct picotm_treemap *treemap) |
Enumerations | |
enum | picotm_rwstate_status { PICOTM_RWSTATE_UNLOCKED, PICOTM_RWSTATE_RDLOCKED, PICOTM_RWSTATE_WRLOCKED } |
#define picotm_arrayat | ( | _array, | |
_i | |||
) |
Returns the address of the element at the specified index in a static C array.
#define picotm_arraybeg | ( | _array | ) |
Returns the beginning of a static C array.
#define picotm_arrayend | ( | _array | ) |
Returns the address after a static C array.
#define picotm_arrayfirst | ( | _array | ) |
Returns the address of the first element in a static C array.
#define picotm_arraylast | ( | _array | ) |
Returns the address of the last element in a static C array.
#define picotm_arraylen | ( | _array | ) |
Computes the number of elements in a static C array.
#define picotm_containerof | ( | ptr, | |
type, | |||
member | |||
) |
Returns the container of a data structure.
ptr | A pointer to a data structure. |
type | The type of the container. |
member | The name of the container's member field. |
#define picotm_ref_count | ( | self | ) |
Reads a reference counter's value.
self | reference counter |
#define picotm_ref_down | ( | self | ) |
Decrements a reference counter.
self | A reference counter |
#define picotm_ref_init | ( | self, | |
count | |||
) |
Initializes a reference counter with the given value.
self | A reference counter |
count | The initial reference count |
#define PICOTM_REF_INITIALIZER | ( | __count | ) |
Initializes a statically allocated reference counter with the given value.
__count | The initial reference count |
#define picotm_ref_up | ( | self | ) |
Increments a reference counter.
self | A reference counter |
#define PICOTM_SHARED_REF16_INITIALIZER | ( | count | ) |
Initializes a static reference counter with the given value.
count | The initial reference count |
#define PICOTM_SHARED_REF16_OBJ_INITIALIZER |
Initializes a statically allocated shared-ref16 object.
#define PICOTM_SHARED_REF_INITIALIZER | ( | __count | ) |
Initializes a statically allocated reference counter with the given value.
__count | The initial reference count |
#define picotm_sizeof_align | ( | __type | ) |
__type | The type. |
typedef bool(* picotm_shared_ref16_obj_condition_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
Invoked by picotm's shared-ref16 object to test if a reference shall be acquired ore released.
ref_obj | The shared-ref16 object. |
data | User data. |
error[out] | Returns an error to the caller. |
typedef void(* picotm_shared_ref16_obj_final_ref_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
Invoked by picotm's shared-ref16 object to finalize an object after releasing the final refrence.
ref_obj | The shared-ref16 object. | |
data | User data. | |
[out] | error | Returns an error to the caller. |
typedef void(* picotm_shared_ref16_obj_first_ref_function) (struct picotm_shared_ref16_obj *ref_obj, void *data, struct picotm_error *error) |
Invoked by picotm's shared-ref16 object to initialize the object after acquiring the first refrence.
ref_obj | The shared-ref16 object. | |
data | User data. | |
[out] | error | Returns an error to the caller. |
typedef uintptr_t(* picotm_shared_treemap_value_create_function) (unsigned long long key, struct picotm_shared_treemap *treemap, struct picotm_error *error) |
Invoked by picotm's shared treemap to create a new shared value.
key | The value's key. | |
treemap | The value's shared treemap. | |
[out] | error | Returns an error from the creator function. |
typedef void(* picotm_shared_treemap_value_destroy_function) (uintptr_t value, struct picotm_shared_treemap *treemap) |
Invoked by picotm's shared treemap to destroy a value.
value | The value to destroy. |
treemap | The value's shared treemap. |
typedef int(* picotm_tab_compare_function) (const void *data0, const void *data1) |
Invoked by table functions for comparing two elements.
data0 | A table element. |
data1 | A table element. |
typedef size_t(* picotm_tabwalk_1_function) (void *data0, struct picotm_error *error) |
Invoked by table functions when walking over the elements of a table.
data0 | The table element. | |
[out] | error | Returns an error from the module. |
typedef size_t(* picotm_tabwalk_2_function) (void *data0, void *data1, struct picotm_error *error) |
Invoked by table functions when walking over the elements of a table.
data0 | The table element. | |
data1 | An additional argument. | |
[out] | error | Returns an error from the module. |
typedef size_t(* picotm_tabwalk_3_function) (void *data0, void *data1, void *data2, struct picotm_error *error) |
Invoked by table functions when walking over the elements of a table.
data0 | The table element. | |
data1 | An additional argument. | |
data2 | An additional argument. | |
[out] | error | Returns an error from the module. |
typedef void(* picotm_treemap_value_call_function) (uintptr_t value, unsigned long long key, struct picotm_treemap *treemap, void *data, struct picotm_error *error) |
Invoked by picotm's treemap to call a value.
value | The value. | |
key | The value's key. | |
treemap | The value's treemap. | |
data | User data. | |
[out] | error | Returns an error from the creator function. |
typedef uintptr_t(* picotm_treemap_value_create_function) (unsigned long long key, struct picotm_treemap *treemap, struct picotm_error *error) |
Invoked by picotm's treemap to create a new value.
key | The value's key. | |
treemap | The value's treemap. | |
[out] | error | Returns an error from the creator function. |
typedef void(* picotm_treemap_value_destroy_function) (uintptr_t value, struct picotm_treemap *treemap) |
Invoked by picotm's treemap to destroy a value.
value | The value to destroy. |
treemap | The value's treemap. |
|
inlinestatic |
addr | A memory address. |
algn | The alignment of the result address. |
|
inlinestatic |
addr | A memory address. |
algn | The alignment of the result address. |
|
inlinestatic |
ptr | A pointer to a memory location. |
algn | The alignment of the result memory location. |
|
inlinestatic |
hi | The higher memory location. |
lo | The lower memory location. |
|
inlinestatic |
ptr | A pointer to a memory location. |
algn | The alignment of the result memory location. |
PICOTM_NOTHROW void picotm_rwlock_init | ( | struct picotm_rwlock * | self | ) |
Initializes a reader-writer lock.
self | The reader-writer lock to initialize. |
PICOTM_NOTHROW void picotm_rwlock_try_rdlock | ( | struct picotm_rwlock * | self, |
struct picotm_error * | error | ||
) |
Tries to acquire a read lock. If the lock could not be acquired, the error parameter will return a conflict.
self | The reader lock to acquire. | |
[out] | error | Returns a error. |
PICOTM_NOTHROW void picotm_rwlock_try_wrlock | ( | struct picotm_rwlock * | self, |
bool | upgrade, | ||
struct picotm_error * | error | ||
) |
Tries to acquire a writer lock or upgrade an acquired reader lock to a writer lock. If the lock could not be acquired, the error parameter will return a conflict.
self | The writer lock to acquire. | |
upgrade | True to upgrade a previously acquired reader lock. | |
[out] | error | Returns a error. |
PICOTM_NOTHROW void picotm_rwlock_uninit | ( | struct picotm_rwlock * | self | ) |
Uninitializes a reader-writer lock.
self | The reader-writer lock to uninitialize. |
PICOTM_NOTHROW void picotm_rwlock_unlock | ( | struct picotm_rwlock * | self | ) |
Releases a reader-writer lock.
self | The reader-writer lock to release. |
PICOTM_NOTHROW enum picotm_rwstate_status picotm_rwstate_get_status | ( | const struct picotm_rwstate * | self | ) |
Returns a reader/writer state's current status.
self | The reader/writer state. |
PICOTM_NOTHROW void picotm_rwstate_init | ( | struct picotm_rwstate * | self | ) |
Initializes a reader-writer state.
self | The reader-writer state to initialize. |
PICOTM_NOTHROW void picotm_rwstate_set_status | ( | struct picotm_rwstate * | self, |
enum picotm_rwstate_status | status | ||
) |
Sets a reader/writer state's status.
self | The reader/writer state. |
status | The status to set. |
PICOTM_NOTHROW void picotm_rwstate_try_rdlock | ( | struct picotm_rwstate * | self, |
struct picotm_rwlock * | rwlock, | ||
struct picotm_error * | error | ||
) |
Tries to acquire a reader lock for the state variable. If the lock could not be acquired, the error parameter will return a conflict.
self | The reader/writer state. | |
rwlock | The reader lock to acquire. | |
[out] | error | Returns a error. |
PICOTM_NOTHROW void picotm_rwstate_try_wrlock | ( | struct picotm_rwstate * | self, |
struct picotm_rwlock * | rwlock, | ||
struct picotm_error * | error | ||
) |
Tries to acquire a writer lock for the state variable or upgrade an acquired reader lock to a writer lock. If the lock could not be acquired, the error parameter will return a conflict.
self | The reader/writer state. | |
rwlock | The reader lock to acquire. | |
[out] | error | Returns a error. |
PICOTM_NOTHROW void picotm_rwstate_uninit | ( | struct picotm_rwstate * | self | ) |
Uninitializes a reader-writer state.
self | The reader-writer state to uninitialize. |
PICOTM_NOTHROW void picotm_rwstate_unlock | ( | struct picotm_rwstate * | self, |
struct picotm_rwlock * | rwlock | ||
) |
Releases a reader-writer lock.
self | The reader/writer state. |
rwlock | The reader/writer lock to release. |
uint16_t picotm_shared_ref16_obj_count | ( | struct picotm_shared_ref16_obj * | self | ) |
Reads the value of a shared-ref16 object's counter.
self | The shared-ref16 object. |
void picotm_shared_ref16_obj_down | ( | struct picotm_shared_ref16_obj * | self, |
void * | data, | ||
picotm_shared_ref16_obj_condition_function | cond, | ||
picotm_shared_ref16_obj_final_ref_function | final_ref | ||
) |
Releases a reference on the shared-ref16 object.
self | The shared-ref16 object. |
data | User data. |
cond | An optional condition to test if the reference should be released. |
final_ref | An optional function to finalize the object when the final reference gets released. |
The conditional and finalizer functions are synchronized with the reference counter. The down function internally locks the shared-ref16 object while performing these operations.
void picotm_shared_ref16_obj_init | ( | struct picotm_shared_ref16_obj * | self, |
struct picotm_error * | error | ||
) |
Initializes a shared-ref16 object.
self | The shared-ref16 object. | |
[out] | error | Returns an error to the caller. |
void picotm_shared_ref16_obj_uninit | ( | struct picotm_shared_ref16_obj * | self | ) |
Uninitializes a shared-ref16 object.
self | The shared-ref16 object. |
void picotm_shared_ref16_obj_up | ( | struct picotm_shared_ref16_obj * | self, |
void * | data, | ||
picotm_shared_ref16_obj_condition_function | cond, | ||
picotm_shared_ref16_obj_first_ref_function | first_ref, | ||
struct picotm_error * | error | ||
) |
Acquires a reference on the shared-ref16 object.
self | The shared-ref16 object. | |
data | User data. | |
cond | An optional condition to test if the reference should be acquired. | |
first_ref | An optional function to initialize the object when the first reference gets acquired. | |
[out] | error | Returns an error to the caller. |
The conditional and initializer functions are synchronized with the reference counter. The up function internally locks the shared-ref16 object while performing these operations.
PICOTM_NOTHROW uintptr_t picotm_shared_treemap_find_value | ( | struct picotm_shared_treemap * | self, |
unsigned long long | key, | ||
picotm_shared_treemap_value_create_function | value_create, | ||
picotm_shared_treemap_value_destroy_function | value_destroy, | ||
struct picotm_error * | error | ||
) |
Retrieves the value for a key from a shared treemap.
self | The shared treemap. | |
key | The value's key. | |
value_create | The creator function for shared values. | |
value_destroy | The destroy function for shared values. | |
[out] | error | Returns an error from the look-up function. |
PICOTM_NOTHROW void picotm_shared_treemap_init | ( | struct picotm_shared_treemap * | self, |
unsigned long | key_nbits, | ||
unsigned long | level_nbits | ||
) |
Initializes a shared treemap.
self | The shared treemap to initialize. |
key_nbits | The maximum number of bits per key. |
level_nbits | The number of bits per directory level. |
PICOTM_NOTHROW void picotm_shared_treemap_uninit | ( | struct picotm_shared_treemap * | self, |
picotm_shared_treemap_value_destroy_function | value_destroy | ||
) |
Uninitializes a shared treemap.
self | The shared treemap to initialize. |
value_destroy | The destroy function for shared values. |
PICOTM_NOTHROW void picotm_tabfree | ( | void * | base | ) |
Free table memory.
base | A pointer to the table's first element. |
PICOTM_NOTHROW void* picotm_tabresize | ( | void * | base, |
size_t | nelems, | ||
size_t | newnelems, | ||
size_t | siz, | ||
struct picotm_error * | error | ||
) |
Allocate or resize table.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
newnelems | The new number of elements in the table. | |
siz | The number of bytes per element. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW size_t picotm_tabrwalk_1 | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tabwalk_1_function | walk, | ||
struct picotm_error * | error | ||
) |
Walk over table in reversed order.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
siz | The number of bytes per element. | |
walk | The call-back function. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW size_t picotm_tabrwalk_2 | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tabwalk_2_function | walk, | ||
void * | data, | ||
struct picotm_error * | error | ||
) |
Walk over table in reversed order.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
siz | The number of bytes per element. | |
walk | The call-back function. | |
data | An additional second argument to the call-back function. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW size_t picotm_tabuniq | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tab_compare_function | compare | ||
) |
Filters out duplicate elements
base | A pointer to the table's first element. |
nelems | The number of elements in the table. |
siz | The number of bytes per element. |
compare | The call-back function for comparing elements. |
PICOTM_NOTHROW size_t picotm_tabwalk_1 | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tabwalk_1_function | walk, | ||
struct picotm_error * | error | ||
) |
Walk over table elements.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
siz | The number of bytes per element. | |
walk | The call-back function. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW size_t picotm_tabwalk_2 | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tabwalk_2_function | walk, | ||
void * | data, | ||
struct picotm_error * | error | ||
) |
Walk over table elements.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
siz | The number of bytes per element. | |
walk | The call-back function. | |
data | An additional second argument to the call-back function. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW size_t picotm_tabwalk_3 | ( | void * | base, |
size_t | nelems, | ||
size_t | siz, | ||
picotm_tabwalk_3_function | walk, | ||
void * | data1, | ||
void * | data2, | ||
struct picotm_error * | error | ||
) |
Walk over table elements.
base | A pointer to the table's first element. | |
nelems | The number of elements in the table. | |
siz | The number of bytes per element. | |
walk | The call-back function. | |
data1 | An additional second argument to the call-back function. | |
data2 | An additional third argument to the call-back function. | |
[out] | error | Returns an error from the module. |
PICOTM_NOTHROW uintptr_t picotm_treemap_find_value | ( | struct picotm_treemap * | self, |
unsigned long long | key, | ||
picotm_treemap_value_create_function | value_create, | ||
struct picotm_error * | error | ||
) |
Retrieves the value for a key from a treemap.
self | The treemap. | |
key | The value's key. | |
value_create | The creator function for values. | |
[out] | error | Returns an error from the look-up function. |
PICOTM_NOTHROW void picotm_treemap_for_each_value | ( | struct picotm_treemap * | self, |
void * | data, | ||
picotm_treemap_value_call_function | value_call, | ||
struct picotm_error * | error | ||
) |
Iterates over all values stored in a treemap.
self | The treemap. | |
data | User data. | |
value_call | The call-back function for values. | |
[out] | error | Returns an error from the look-up function. |
PICOTM_NOTHROW void picotm_treemap_init | ( | struct picotm_treemap * | self, |
unsigned long | level_nbits | ||
) |
Initializes a treemap.
self | The treemap to initialize. |
level_nbits | The number of bits per directory level. |
PICOTM_NOTHROW void picotm_treemap_uninit | ( | struct picotm_treemap * | self, |
picotm_treemap_value_destroy_function | value_destroy | ||
) |
Uninitializes a treemap.
self | The treemap to initialize. |
value_destroy | The destroy function for values. |