1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Add _lv_mem_buf as root pointer for gc

This commit is contained in:
Amir Gonnen 2019-12-26 22:12:18 +02:00
parent 4267acba0d
commit 0af0994da1
4 changed files with 25 additions and 20 deletions

View File

@ -29,12 +29,11 @@
/**********************
* STATIC VARIABLES
**********************/
lv_mem_buf_t _lv_mem_buf[LV_MEM_BUF_MAX_NUM];
#if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
LV_ROOTS
#endif /* LV_ENABLE_GC */
/**********************
* MACROS
**********************/

View File

@ -24,8 +24,6 @@ extern "C" {
* DEFINES
*********************/
extern lv_mem_buf_t _lv_mem_buf[LV_MEM_BUF_MAX_NUM];
#define LV_ITERATE_ROOTS(f) \
f(lv_ll_t, _lv_task_ll) /*Linked list to store the lv_tasks*/ \
f(lv_ll_t, _lv_disp_ll) /*Linked list of screens*/ \
@ -37,6 +35,7 @@ extern lv_mem_buf_t _lv_mem_buf[LV_MEM_BUF_MAX_NUM];
f(lv_ll_t, _lv_img_defoder_ll) \
f(lv_img_cache_entry_t*, _lv_img_cache_array) \
f(void*, _lv_task_act) \
f(lv_mem_buf_arr_t , _lv_mem_buf) \
#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name;
#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)

View File

@ -16,6 +16,10 @@
#include LV_MEM_CUSTOM_INCLUDE
#endif
#if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */
/*********************
* DEFINES
*********************/
@ -403,23 +407,23 @@ void * lv_mem_buf_get(uint32_t size)
/*Try to find a free buffer with suitable size */
uint8_t i;
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
if(_lv_mem_buf[i].used == 0 && _lv_mem_buf[i].size >= size) {
_lv_mem_buf[i].used = 1;
return _lv_mem_buf[i].p;
if(LV_GC_ROOT(_lv_mem_buf[i]).used == 0 && LV_GC_ROOT(_lv_mem_buf[i]).size >= size) {
LV_GC_ROOT(_lv_mem_buf[i]).used = 1;
return LV_GC_ROOT(_lv_mem_buf[i]).p;
}
}
/*Reallocate a free buffer*/
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
if(_lv_mem_buf[i].used == 0) {
_lv_mem_buf[i].used = 1;
_lv_mem_buf[i].size = size;
if(LV_GC_ROOT(_lv_mem_buf[i]).used == 0) {
LV_GC_ROOT(_lv_mem_buf[i]).used = 1;
LV_GC_ROOT(_lv_mem_buf[i]).size = size;
/*if this fails you probably need to increase your LV_MEM_SIZE/heap size*/
_lv_mem_buf[i].p = lv_mem_realloc(_lv_mem_buf[i].p, size);
if(_lv_mem_buf[i].p == NULL) {
LV_GC_ROOT(_lv_mem_buf[i]).p = lv_mem_realloc(LV_GC_ROOT(_lv_mem_buf[i]).p, size);
if(LV_GC_ROOT(_lv_mem_buf[i]).p == NULL) {
LV_LOG_ERROR("lv_mem_buf_get: Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size)")
}
return _lv_mem_buf[i].p;
return LV_GC_ROOT(_lv_mem_buf[i]).p;
}
}
@ -436,8 +440,8 @@ void lv_mem_buf_release(void * p)
{
uint8_t i;
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
if(_lv_mem_buf[i].p == p) {
_lv_mem_buf[i].used = 0;
if(LV_GC_ROOT(_lv_mem_buf[i]).p == p) {
LV_GC_ROOT(_lv_mem_buf[i]).used = 0;
return;
}
}
@ -452,11 +456,11 @@ void lv_mem_buf_free_all(void)
{
uint8_t i;
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
if(_lv_mem_buf[i].p) {
lv_mem_free(_lv_mem_buf[i].p);
_lv_mem_buf[i].p = NULL;
_lv_mem_buf[i].used = 0;
_lv_mem_buf[i].size = 0;
if(LV_GC_ROOT(_lv_mem_buf[i]).p) {
lv_mem_free(LV_GC_ROOT(_lv_mem_buf[i]).p);
LV_GC_ROOT(_lv_mem_buf[i]).p = NULL;
LV_GC_ROOT(_lv_mem_buf[i]).used = 0;
LV_GC_ROOT(_lv_mem_buf[i]).size = 0;
}
}
}

View File

@ -52,6 +52,9 @@ typedef struct {
uint8_t used :1;
}lv_mem_buf_t;
typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
extern lv_mem_buf_arr_t _lv_mem_buf;
/**********************
* GLOBAL PROTOTYPES
**********************/