heap: make compatible with non-OS builds, remove target dependence

This commit is contained in:
Ivan Grokhotkov
2019-12-18 17:04:49 +01:00
parent acca61c714
commit 3285ed116d
7 changed files with 43 additions and 22 deletions

View File

@@ -18,12 +18,10 @@
#include "esp_log.h"
#include "multi_heap.h"
#include "multi_heap_platform.h"
#include "esp_heap_caps_init.h"
#include "soc/soc_memory_layout.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static const char *TAG = "heap_init";
/* Linked-list of registered heaps */
@@ -107,7 +105,7 @@ void heap_caps_init(void)
memcpy(heap->caps, type->caps, sizeof(heap->caps));
heap->start = region->start;
heap->end = region->start + region->size;
vPortCPUInitializeMutex(&heap->heap_mux);
MULTI_HEAP_LOCK_INIT(&heap->heap_mux);
if (type->startup_stack) {
/* Will be registered when OS scheduler starts */
heap->heap = NULL;
@@ -216,7 +214,7 @@ esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start,
memcpy(p_new->caps, caps, sizeof(p_new->caps));
p_new->start = start;
p_new->end = end;
vPortCPUInitializeMutex(&p_new->heap_mux);
MULTI_HEAP_LOCK_INIT(&p_new->heap_mux);
p_new->heap = multi_heap_register((void *)start, end - start);
SLIST_NEXT(p_new, next) = NULL;
if (p_new->heap == NULL) {
@@ -228,10 +226,10 @@ esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start,
/* (This insertion is atomic to registered_heaps, so
we don't need to worry about thread safety for readers,
only for writers. */
static _lock_t registered_heaps_write_lock;
_lock_acquire(&registered_heaps_write_lock);
static multi_heap_lock_t registered_heaps_write_lock = MULTI_HEAP_LOCK_STATIC_INITIALIZER;
MULTI_HEAP_LOCK(&registered_heaps_write_lock);
SLIST_INSERT_HEAD(&registered_heaps, p_new, next);
_lock_release(&registered_heaps_write_lock);
MULTI_HEAP_UNLOCK(&registered_heaps_write_lock);
err = ESP_OK;