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:
parent
b2f1bbed88
commit
b7dbe1a51e
1 changed files with 13 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue