Usage of semaphore for all lv_.. apis

Hello all,

I am using this GitHub - lvgl/lv_port_pc_vscode simulator project on Linux, and I have created UI using the SLS the lvgl version I am using is v8.3

In the main. c the application code contains 3 threads one to call lv_tick_in, one for lv_timer_handler at a fixed time duration and the third thread contains my application logic to manage the GUI by moving the lvgl objects

Now my concern is that initially when I ran the project it worked as expected but the CPU usage I was getting was above 95% and the FPS varied between 5-10 FPS, in the lv_conf.h file I have disabled the building of the example and enabled the LOGS by defining #define LV_LOG_LEVEL LV_LOG_LEVEL_WARN in lv_conf.h

Additionally, while the application was running I was getting some errors as shown in below photos

Then I searched online for this error and found that I need to use a semaphore or mutex to guard all the lv_… APIs as LVGL is not fully thread safe(as mentioned here Operating system and interrupts — LVGL documentation) after doing so I was able to get 33 fps and CPU usage below 5%

So my question is my approach of using the semaphore is correct or do I have to do something else to get rid of the error, high CPU usage and low FPS

Thanks

why this complicated 3T ?

Tick inc is safe and can be on os with internal timers be aliased to get tick from OS.

handler and gui is designed to operate in same only one thread.

you mean that i can call lv_tick_in in os timer and call lv_timer_handler and all other lv_… apis in same thread?

I can not call the lv_timer_handler and other LVGL APIs in the same thread due to some other constrains of the application, so is it ok to call lv_timer_handler and use mutex for synchronisation?

Explain why?

I am getting the input from the buttons to move the objects and update them, which is event-based and some other objects are moving at different timings, for lv_timer_handler we have to call it at an interval

even if I manage to call lv_timer_handler and other APIs in a single thread then a semaphore is not required, right?

LVGL for buttons have indev system and or you can if in while where is lv_timer_hadler no problem.
Foe repeatly exist lv_timers system …
Yes no semaphore/lock then.

Try start with understand how lvgl works.
Stage 1 setup
Stage 2 guiloop
Stage 3 background.

In setup you can add many threads , but only one with guiloop and manipulate lv.
If you use arduino loop is created task designed for this , but you can use other
And background is inc_tick or other tick measure methods, another background is dma lcd driver parts etc.

Example loop symbolic code :

void loop()
{

 lv_timer_handler();
  delay(5);
//all next code must took micro seconds
//for slow create next threads and set event markers for show results
if(once) {
                //here for example start lv_timers = periodical lv operations callbacks
             }
if(event1) {

                }

}

and what do lv_time_handler = do all lvgl jobs:

  1. ask lvgl core is any callback wait do it
  2. is tick over set indev refresh … do indev scan …
  3. is tick over screen refresh … do if somethink changed
  4. is an lv timer … do it
  5. maybe other or nothing to do return