Skip to content

Commit

Permalink
Revert "🐛 Fix race and an abandoned mutex (#180)"
Browse files Browse the repository at this point in the history
This reverts commit a02cefc.
  • Loading branch information
HotelCalifornia authored Nov 21, 2019
1 parent a02cefc commit f95b42f
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/display/lv_misc/lv_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,17 @@ 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;

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;
if(task_handler_mutex) return;
task_handler_mutex = true;

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 @@ -158,7 +148,7 @@ LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)

}

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

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

/**
Expand Down

0 comments on commit f95b42f

Please sign in to comment.