mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Add _lv_mem_buf as root pointer for gc
This commit is contained in:
parent
4267acba0d
commit
0af0994da1
@ -29,12 +29,11 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
lv_mem_buf_t _lv_mem_buf[LV_MEM_BUF_MAX_NUM];
|
|
||||||
|
|
||||||
|
|
||||||
#if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
|
#if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
|
||||||
LV_ROOTS
|
LV_ROOTS
|
||||||
#endif /* LV_ENABLE_GC */
|
#endif /* LV_ENABLE_GC */
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -24,8 +24,6 @@ extern "C" {
|
|||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
|
||||||
extern lv_mem_buf_t _lv_mem_buf[LV_MEM_BUF_MAX_NUM];
|
|
||||||
|
|
||||||
#define LV_ITERATE_ROOTS(f) \
|
#define LV_ITERATE_ROOTS(f) \
|
||||||
f(lv_ll_t, _lv_task_ll) /*Linked list to store the lv_tasks*/ \
|
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*/ \
|
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_ll_t, _lv_img_defoder_ll) \
|
||||||
f(lv_img_cache_entry_t*, _lv_img_cache_array) \
|
f(lv_img_cache_entry_t*, _lv_img_cache_array) \
|
||||||
f(void*, _lv_task_act) \
|
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_DEFINE_ROOT(root_type, root_name) root_type root_name;
|
||||||
#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)
|
#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include LV_MEM_CUSTOM_INCLUDE
|
#include LV_MEM_CUSTOM_INCLUDE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LV_GC_INCLUDE)
|
||||||
|
#include LV_GC_INCLUDE
|
||||||
|
#endif /* LV_ENABLE_GC */
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
@ -403,23 +407,23 @@ void * lv_mem_buf_get(uint32_t size)
|
|||||||
/*Try to find a free buffer with suitable size */
|
/*Try to find a free buffer with suitable size */
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||||
if(_lv_mem_buf[i].used == 0 && _lv_mem_buf[i].size >= size) {
|
if(LV_GC_ROOT(_lv_mem_buf[i]).used == 0 && LV_GC_ROOT(_lv_mem_buf[i]).size >= size) {
|
||||||
_lv_mem_buf[i].used = 1;
|
LV_GC_ROOT(_lv_mem_buf[i]).used = 1;
|
||||||
return _lv_mem_buf[i].p;
|
return LV_GC_ROOT(_lv_mem_buf[i]).p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Reallocate a free buffer*/
|
/*Reallocate a free buffer*/
|
||||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||||
if(_lv_mem_buf[i].used == 0) {
|
if(LV_GC_ROOT(_lv_mem_buf[i]).used == 0) {
|
||||||
_lv_mem_buf[i].used = 1;
|
LV_GC_ROOT(_lv_mem_buf[i]).used = 1;
|
||||||
_lv_mem_buf[i].size = size;
|
LV_GC_ROOT(_lv_mem_buf[i]).size = size;
|
||||||
/*if this fails you probably need to increase your LV_MEM_SIZE/heap 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);
|
LV_GC_ROOT(_lv_mem_buf[i]).p = lv_mem_realloc(LV_GC_ROOT(_lv_mem_buf[i]).p, size);
|
||||||
if(_lv_mem_buf[i].p == NULL) {
|
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)")
|
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;
|
uint8_t i;
|
||||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||||
if(_lv_mem_buf[i].p == p) {
|
if(LV_GC_ROOT(_lv_mem_buf[i]).p == p) {
|
||||||
_lv_mem_buf[i].used = 0;
|
LV_GC_ROOT(_lv_mem_buf[i]).used = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,11 +456,11 @@ void lv_mem_buf_free_all(void)
|
|||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||||
if(_lv_mem_buf[i].p) {
|
if(LV_GC_ROOT(_lv_mem_buf[i]).p) {
|
||||||
lv_mem_free(_lv_mem_buf[i].p);
|
lv_mem_free(LV_GC_ROOT(_lv_mem_buf[i]).p);
|
||||||
_lv_mem_buf[i].p = NULL;
|
LV_GC_ROOT(_lv_mem_buf[i]).p = NULL;
|
||||||
_lv_mem_buf[i].used = 0;
|
LV_GC_ROOT(_lv_mem_buf[i]).used = 0;
|
||||||
_lv_mem_buf[i].size = 0;
|
LV_GC_ROOT(_lv_mem_buf[i]).size = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,9 @@ typedef struct {
|
|||||||
uint8_t used :1;
|
uint8_t used :1;
|
||||||
}lv_mem_buf_t;
|
}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
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user