mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
memarray: Add memarray_available function
This commit is contained in:
parent
5495da5840
commit
a2ce2e9cfb
@ -20,7 +20,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -110,6 +110,15 @@ static inline void memarray_free(memarray_t *mem, void *ptr)
|
||||
mem->free_data = ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of blocks available
|
||||
*
|
||||
* @param[in] mem memarray pool
|
||||
*
|
||||
* @returns Number of elements available in the memarray pool
|
||||
*/
|
||||
size_t memarray_available(memarray_t *mem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -31,3 +31,14 @@ void memarray_init(memarray_t *mem, void *data, size_t size, size_t num)
|
||||
memarray_free(mem, element);
|
||||
}
|
||||
}
|
||||
|
||||
size_t memarray_available(memarray_t *mem)
|
||||
{
|
||||
size_t num = 0;
|
||||
void **element = &mem->free_data;
|
||||
while (*element) {
|
||||
element = (void**)*element;
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user