|
TARFS 0.1.5
Read-only TAR filesystem for ESP32
|
#include <stdint.h>#include <stdatomic.h>#include <stdlib.h>#include <stdbool.h>Go to the source code of this file.
Typedefs | |
| typedef unsigned int | refc_type_t |
| Use case: | |
Functions | |
| typedef | _Atomic (refc_type_t) refc_t |
| Atomic reference counter type. | |
| static void | initref (refc_t *ref) |
| Initialize reference counter. | |
| static void | initrefn (refc_t *ref, refc_type_t n) |
| Initialize reference counter with specified value. | |
| refc_type_t | addrefn (refc_t *ref, refc_type_t n) |
| Increase reference counter by specified value. | |
| static refc_type_t | addref (refc_t *ref) |
| Increase reference counter. | |
| refc_type_t | unrefxn (refc_t *r, void *object, refc_type_t n, void(*dtor)(void *)) |
| Release references and optionally destroy object. | |
| static refc_type_t | unref (refc_t *ref, void *object) |
| Release reference and destroy object if no references remain. | |
| static refc_type_t | unrefn (refc_t *ref, void *object, refc_type_t n) |
| Release multiple references and destroy object if no references remain. | |
| static refc_type_t | unrefx (refc_t *ref, void *object, void(*dtor)(void *)) |
| Release reference and call custom destructor. | |
| static refc_type_t | readref (refc_t *r) |
| Read refcounter atomically. | |
| typedef unsigned int refc_type_t |
Use case:
Reference counter type.
Native CPU integer size is usually the fastest option.
| typedef _Atomic | ( | refc_type_t | ) |
Atomic reference counter type.
|
inlinestatic |
Increase reference counter.
Increase reference counter by 1.
| ref | : pointer to reference counter. |
Definition at line 129 of file refc.h.
References addrefn().
Referenced by tarfs_addref().
| refc_type_t addrefn | ( | refc_t * | ref, |
| refc_type_t | n ) |
Increase reference counter by specified value.
This function attempts to increase reference counter by /n/.
| ref | : pointer to reference counter. |
| n | : number of references to add. |
(see refc.h for full comments)
This function attempts to increase reference counter by n (user defined integer type variable or integer literal, e.g. addrefn(&ref, 10)).
Definition at line 39 of file refc.c.
Referenced by addref().
|
inlinestatic |
Initialize reference counter.
Set reference counter value to 1.
| ref | : pointer to reference counter. |
Definition at line 72 of file refc.h.
Referenced by tarfs_mount_memory().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Release reference and destroy object if no references remain.
This function is equivalent to:
unrefxn(ref, object, 1, free);
| ref | : pointer to reference counter. |
| object | : object controlled by the reference counter. |
Definition at line 190 of file refc.h.
References unrefxn().
|
inlinestatic |
Release multiple references and destroy object if no references remain.
This function is equivalent to:
unrefxn(ref, object, n, free);
| ref | : pointer to reference counter. |
| object | : object controlled by the reference counter. |
| n | : number of references to release. |
Definition at line 209 of file refc.h.
References unrefxn().
|
inlinestatic |
Release reference and call custom destructor.
This function is equivalent to:
unrefxn(ref, object, 1, dtor);
| ref | : pointer to reference counter. |
| object | : object controlled by the reference counter. |
| dtor | : destructor function. |
Definition at line 227 of file refc.h.
References unrefxn().
Referenced by tarfs_unref().
| refc_type_t unrefxn | ( | refc_t * | r, |
| void * | object, | ||
| refc_type_t | n, | ||
| void(* | dtor )(void *) ) |
Release references and optionally destroy object.
Decrease reference counter by /n/. When reference counter reaches zero, destructor function /dtor/ is called.
| r | : pointer to reference counter. |
| object | : object controlled by the reference counter. |
| n | : number of references to release. If n is zero, function performs a liveness check. If /n/ is greater than current reference count, reference counter is decremented until it reaches zero. Destructor function is called exactly once. |
| dtor | : destructor function. standart C function free() can be used here If dtor is NULL, object is not destroyed even when reference counter reaches zero, possibly creating a memory leak. |
Value of 0 is returned when some fatal eeror is occured: attempt to unref the object which is being deleted; pointer to the r is NULL
(see refc.h for full comments)
Decrease reference counter by /n/. When reference counter reaches zero, destructor function /dtor/ is called: in case of n > 0, object is unreferenced one by one so the destructor is called exactly once, even if n is larger than current ref counter value