1
0
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:
Koen Zandberg 2021-01-15 11:25:03 +01:00
parent 5495da5840
commit a2ce2e9cfb
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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;
}