Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix race and an abandoned mutex #180

Merged
merged 7 commits into from
Nov 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/display/lv_misc/lv_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@ void lv_task_init(void)
LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)
{
LV_LOG_TRACE("lv_task_handler started");
bool task_run = __atomic_load_n(&lv_task_run, __ATOMIC_ACQUIRE);

if(task_run == false)
{
LV_LOG_TRACE("lv_task_handler bailed early, task run false");
return;
}

/*Avoid concurrent running of the task handler*/
static bool task_handler_mutex = false;
if(task_handler_mutex) return;
task_handler_mutex = true;

bool expected = false;
bool toSet = true;
bool alreadyTaken = __atomic_compare_exchange(&task_handler_mutex, &expected, &toSet,/* weak*/ false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);

if (alreadyTaken) return;

static uint32_t idle_period_start = 0;
static uint32_t handler_start = 0;
static uint32_t busy_time = 0;

if(lv_task_run == false) return;

handler_start = lv_tick_get();

Expand Down Expand Up @@ -148,7 +158,7 @@ LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)

}

task_handler_mutex = false; /*Release the mutex*/
__atomic_store_n(&task_handler_mutex, false, __ATOMIC_RELEASE);

LV_LOG_TRACE("lv_task_handler ready");
}
Expand Down Expand Up @@ -284,7 +294,7 @@ void lv_task_reset(lv_task_t * lv_task_p)
*/
void lv_task_enable(bool en)
{
lv_task_run = en;
__atomic_store_n(&lv_task_run, en, __ATOMIC_RELAXED);
}

/**
Expand Down