lvgl: add locking for the sys heap

The sys_heap layer doesn't provide any locking mechanism. Add a spin_lock
around the calls to sys_heap functions.

Suggested-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
This commit is contained in:
Bartosz Golaszewski 2021-12-17 18:39:22 +01:00 committed by Carles Cufí
commit b7dbe1a51e

View file

@ -16,15 +16,27 @@
static char lvgl_heap_mem[HEAP_BYTES] __aligned(8);
static struct sys_heap lvgl_heap;
static struct k_spinlock lvgl_heap_lock;
void *lvgl_malloc(size_t size)
{
return sys_heap_alloc(&lvgl_heap, size);
k_spinlock_key_t key;
void *ret;
key = k_spin_lock(&lvgl_heap_lock);
ret = sys_heap_alloc(&lvgl_heap, size);
k_spin_unlock(&lvgl_heap_lock, key);
return ret;
}
void lvgl_free(void *ptr)
{
k_spinlock_key_t key;
key = k_spin_lock(&lvgl_heap_lock);
sys_heap_free(&lvgl_heap, ptr);
k_spin_unlock(&lvgl_heap_lock, key);
}
static int lvgl_heap_init(const struct device *unused)