Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor alloc.h to not need forward declaration #245

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef __METAL_ALLOC__H__
#define __METAL_ALLOC__H__

#include <metal/system/@PROJECT_SYSTEM@/alloc.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -27,21 +29,25 @@ extern "C" {
* @param[in] size size in byte of requested memory
* @return memory pointer, or 0 if it failed to allocate
*/
static inline void *metal_allocate_memory(unsigned int size);
static inline void *metal_allocate_memory(unsigned int size)
{
return __metal_allocate_memory(size);
}

/**
* @brief free the memory previously allocated
*
* @param[in] ptr pointer to memory
*/
static inline void metal_free_memory(void *ptr);
static inline void metal_free_memory(void *ptr)
{
__metal_free_memory(ptr);
}

/** @} */

#ifdef __cplusplus
}
#endif

#include <metal/system/@PROJECT_SYSTEM@/alloc.h>

#endif /* __METAL_ALLOC__H__ */
4 changes: 2 additions & 2 deletions lib/system/freertos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
extern "C" {
#endif

static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return pvPortMalloc(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
vPortFree(ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/system/generic/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
extern "C" {
#endif

static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return malloc(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
free(ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/system/linux/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
extern "C" {
#endif

static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return malloc(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
free(ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/system/nuttx/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
extern "C" {
#endif

static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return kmm_malloc(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
kmm_free(ptr);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/system/zephyr/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ extern "C" {
#endif

#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return k_malloc(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
k_free(ptr);
}
Expand All @@ -38,12 +38,12 @@ static inline void metal_free_memory(void *ptr)
void *metal_zephyr_allocate_memory(unsigned int size);
void metal_zephyr_free_memory(void *ptr);

static inline void *metal_allocate_memory(unsigned int size)
static inline void *__metal_allocate_memory(unsigned int size)
{
return metal_zephyr_allocate_memory(size);
}

static inline void metal_free_memory(void *ptr)
static inline void __metal_free_memory(void *ptr)
{
metal_zephyr_free_memory(ptr);
}
Expand Down