Skip to content

Commit

Permalink
Use Zephyr heap for Zephyr targets
Browse files Browse the repository at this point in the history
  • Loading branch information
pawszw authored and mrdeep1 committed Aug 28, 2024
1 parent 1c97907 commit abd0a02
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions src/coap_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,65 @@ coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
}
#else /* ! RIOT_VERSION && ! MODULE_MEMARRAY */

#if defined(HAVE_MALLOC) || defined(__MINGW32__)
#if defined(__ZEPHYR__)

#include <zephyr/kernel.h>

void
coap_memory_init(void) {
}

void *
coap_malloc_type(coap_memory_tag_t type, size_t size) {
void *ptr;

(void)type;
ptr = k_malloc(size);
#if COAP_MEMORY_TYPE_TRACK
assert(type < COAP_MEM_TAG_LAST);
if (ptr) {
track_counts[type]++;
if (track_counts[type] > peak_counts[type])
peak_counts[type] = track_counts[type];
} else {
fail_counts[type]++;
}
#endif /* COAP_MEMORY_TYPE_TRACK */
return ptr;
}

void *
coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
void *ptr;

(void)type;
ptr = k_realloc(p, size);
#if COAP_MEMORY_TYPE_TRACK
if (ptr) {
assert(type < COAP_MEM_TAG_LAST);
if (!p)
track_counts[type]++;
if (track_counts[type] > peak_counts[type])
peak_counts[type] = track_counts[type];
} else {
fail_counts[type]++;
}
#endif /* COAP_MEMORY_TYPE_TRACK */
return ptr;
}

void
coap_free_type(coap_memory_tag_t type, void *p) {
(void)type;
#if COAP_MEMORY_TYPE_TRACK
assert(type < COAP_MEM_TAG_LAST);
if (p)
track_counts[type]--;
#endif /* COAP_MEMORY_TYPE_TRACK */
k_free(p);
}

#elif defined(HAVE_MALLOC) || defined(__MINGW32__)
#include <stdlib.h>

void
Expand Down Expand Up @@ -537,7 +595,7 @@ coap_free_type(coap_memory_tag_t type, void *p) {
free(p);
}

#else /* ! HAVE_MALLOC && !__MINGW32__ */
#else /* ! HAVE_MALLOC && !__MINGW32__ && !__ZEPHYR__*/

#ifdef WITH_CONTIKI
#include "lib/heapmem.h"
Expand Down

0 comments on commit abd0a02

Please sign in to comment.