EtherLib/dynmem.c
Wiesner András c165389369 - Timer checked, found no (obvious) bugs
- Dynmem mutex added
- IP reassembler fixed
- More explanation added in comments to the PacketSieve
2023-11-04 20:12:45 +01:00

31 lines
802 B
C

#include "dynmem.h"
#include "global_state.h"
#include "utils.h"
#if !defined(ETHLIB_MEMORY_POOL_ATTRIBUTES)
static uint8_t sDynMemPool[ETHLIB_MEMORY_POOL_TOTAL_SIZE];
#else
static uint8_t sDynMemPool[ETHLIB_MEMORY_POOL_TOTAL_SIZE] __attribute__((ETHLIB_MEMORY_POOL_ATTRIBUTES));
#endif
static ETHLIB_OS_MTX_TYPE dynmem_mtx;
void dynmem_init() {
ETHLIB_OS_MTX_CREATE(&dynmem_mtx);
E.mp = mp_init(sDynMemPool, ETHLIB_MEMORY_POOL_TOTAL_SIZE);
ASSERT_NULL(E.mp);
}
void *dynmem_alloc_(uint32_t size) {
ETHLIB_OS_MTX_LOCK(&dynmem_mtx);
void * p = mp_alloc(E.mp, size);
ETHLIB_OS_MTX_UNLOCK(&dynmem_mtx);
return p;
}
void dynmem_free_(const void *ptr) {
ETHLIB_OS_MTX_LOCK(&dynmem_mtx);
mp_free(E.mp, (const uint8_t *) ptr);
ETHLIB_OS_MTX_UNLOCK(&dynmem_mtx);
}