mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
fix(freertos) Cleanup the check for initialization of mutex and condition variable.
Signed-off-by: Nicușor Cîțu <nicusor.citu@nxp.com>
This commit is contained in:
parent
c146d65a12
commit
4f0e5c8970
@ -38,10 +38,14 @@
|
|||||||
|
|
||||||
static void prvRunThread(void * pxArg);
|
static void prvRunThread(void * pxArg);
|
||||||
|
|
||||||
static void prvInitializeMutex(lv_mutex_t * pxMutex);
|
static void prvMutexInit(lv_mutex_t * pxMutex);
|
||||||
|
|
||||||
|
static void prvCheckMutexInit(lv_mutex_t * pxMutex);
|
||||||
|
|
||||||
#if !USE_FREERTOS_TASK_NOTIFY
|
#if !USE_FREERTOS_TASK_NOTIFY
|
||||||
static void prvInitializeCond(lv_thread_sync_t * pxCond);
|
static void prvCondInit(lv_thread_sync_t * pxCond);
|
||||||
|
|
||||||
|
static void prvCheckCondInit(lv_thread_sync_t * pxCond);
|
||||||
|
|
||||||
static void prvTestAndDecrement(lv_thread_sync_t * pxCond,
|
static void prvTestAndDecrement(lv_thread_sync_t * pxCond,
|
||||||
uint32_t ulLocalWaitingThreads);
|
uint32_t ulLocalWaitingThreads);
|
||||||
@ -92,15 +96,7 @@ lv_res_t lv_thread_delete(lv_thread_t * pxThread)
|
|||||||
|
|
||||||
lv_res_t lv_mutex_init(lv_mutex_t * pxMutex)
|
lv_res_t lv_mutex_init(lv_mutex_t * pxMutex)
|
||||||
{
|
{
|
||||||
pxMutex->xMutex = xSemaphoreCreateMutex();
|
prvMutexInit(pxMutex);
|
||||||
|
|
||||||
/* Ensure that the FreeRTOS mutex was successfully created. */
|
|
||||||
if(pxMutex->xMutex == NULL) {
|
|
||||||
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
|
||||||
return LV_RES_INV;
|
|
||||||
}
|
|
||||||
|
|
||||||
pxMutex->xIsInitialized = pdTRUE;
|
|
||||||
|
|
||||||
return LV_RES_OK;
|
return LV_RES_OK;
|
||||||
}
|
}
|
||||||
@ -108,7 +104,7 @@ lv_res_t lv_mutex_init(lv_mutex_t * pxMutex)
|
|||||||
lv_res_t lv_mutex_lock(lv_mutex_t * pxMutex)
|
lv_res_t lv_mutex_lock(lv_mutex_t * pxMutex)
|
||||||
{
|
{
|
||||||
/* If mutex in uninitialized, perform initialization. */
|
/* If mutex in uninitialized, perform initialization. */
|
||||||
prvInitializeMutex(pxMutex);
|
prvCheckMutexInit(pxMutex);
|
||||||
|
|
||||||
BaseType_t xMutexTakeStatus = xSemaphoreTake(pxMutex->xMutex, portMAX_DELAY);
|
BaseType_t xMutexTakeStatus = xSemaphoreTake(pxMutex->xMutex, portMAX_DELAY);
|
||||||
if(xMutexTakeStatus != pdTRUE) {
|
if(xMutexTakeStatus != pdTRUE) {
|
||||||
@ -122,7 +118,7 @@ lv_res_t lv_mutex_lock(lv_mutex_t * pxMutex)
|
|||||||
lv_res_t lv_mutex_lock_isr(lv_mutex_t * pxMutex)
|
lv_res_t lv_mutex_lock_isr(lv_mutex_t * pxMutex)
|
||||||
{
|
{
|
||||||
/* If mutex in uninitialized, perform initialization. */
|
/* If mutex in uninitialized, perform initialization. */
|
||||||
prvInitializeMutex(pxMutex);
|
prvCheckMutexInit(pxMutex);
|
||||||
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
@ -144,7 +140,7 @@ lv_res_t lv_mutex_lock_isr(lv_mutex_t * pxMutex)
|
|||||||
lv_res_t lv_mutex_unlock(lv_mutex_t * pxMutex)
|
lv_res_t lv_mutex_unlock(lv_mutex_t * pxMutex)
|
||||||
{
|
{
|
||||||
/* If mutex in uninitialized, perform initialization. */
|
/* If mutex in uninitialized, perform initialization. */
|
||||||
prvInitializeMutex(pxMutex);
|
prvCheckMutexInit(pxMutex);
|
||||||
|
|
||||||
BaseType_t xMutexGiveStatus = xSemaphoreGive(pxMutex->xMutex);
|
BaseType_t xMutexGiveStatus = xSemaphoreGive(pxMutex->xMutex);
|
||||||
if(xMutexGiveStatus != pdTRUE) {
|
if(xMutexGiveStatus != pdTRUE) {
|
||||||
@ -169,25 +165,7 @@ lv_res_t lv_thread_sync_init(lv_thread_sync_t * pxCond)
|
|||||||
/* Store the handle of the calling task. */
|
/* Store the handle of the calling task. */
|
||||||
pxCond->xTaskToNotify = xTaskGetCurrentTaskHandle();
|
pxCond->xTaskToNotify = xTaskGetCurrentTaskHandle();
|
||||||
#else
|
#else
|
||||||
pxCond->xCondWaitSemaphore = xSemaphoreCreateCounting(ulMAX_COUNT, 0U);
|
prvCondInit(pxCond);
|
||||||
|
|
||||||
/* Ensure that the FreeRTOS semaphore was successfully created. */
|
|
||||||
if(pxCond->xCondWaitSemaphore == NULL) {
|
|
||||||
LV_LOG_ERROR("xSemaphoreCreateCounting failed!");
|
|
||||||
return LV_RES_INV;
|
|
||||||
}
|
|
||||||
|
|
||||||
pxCond->xSyncMutex = xSemaphoreCreateMutex();
|
|
||||||
|
|
||||||
/* Ensure that the FreeRTOS mutex was successfully created. */
|
|
||||||
if(pxCond->xSyncMutex == NULL) {
|
|
||||||
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
|
||||||
return LV_RES_INV;
|
|
||||||
}
|
|
||||||
|
|
||||||
pxCond->ulWaitingThreads = 0;
|
|
||||||
pxCond->xSyncSignal = pdFALSE;
|
|
||||||
pxCond->xIsInitialized = pdTRUE;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return LV_RES_OK;
|
return LV_RES_OK;
|
||||||
@ -206,7 +184,7 @@ lv_res_t lv_thread_sync_wait(lv_thread_sync_t * pxCond)
|
|||||||
uint32_t ulLocalWaitingThreads;
|
uint32_t ulLocalWaitingThreads;
|
||||||
|
|
||||||
/* If the cond is uninitialized, perform initialization. */
|
/* If the cond is uninitialized, perform initialization. */
|
||||||
prvInitializeCond(pxCond);
|
prvCheckCondInit(pxCond);
|
||||||
|
|
||||||
/* Acquire the mutex. */
|
/* Acquire the mutex. */
|
||||||
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
|
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
|
||||||
@ -269,7 +247,7 @@ lv_res_t lv_thread_sync_signal(lv_thread_sync_t * pxCond)
|
|||||||
xTaskNotifyGive(pxCond->xTaskToNotify);
|
xTaskNotifyGive(pxCond->xTaskToNotify);
|
||||||
#else
|
#else
|
||||||
/* If the cond is uninitialized, perform initialization. */
|
/* If the cond is uninitialized, perform initialization. */
|
||||||
prvInitializeCond(pxCond);
|
prvCheckCondInit(pxCond);
|
||||||
|
|
||||||
/* Acquire the mutex. */
|
/* Acquire the mutex. */
|
||||||
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
|
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
|
||||||
@ -336,7 +314,21 @@ static void prvRunThread(void * pxArg)
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prvInitializeMutex(lv_mutex_t * pxMutex)
|
static void prvMutexInit(lv_mutex_t * pxMutex)
|
||||||
|
{
|
||||||
|
pxMutex->xMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
|
/* Ensure that the FreeRTOS mutex was successfully created. */
|
||||||
|
if(pxMutex->xMutex == NULL) {
|
||||||
|
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mutex successfully created. */
|
||||||
|
pxMutex->xIsInitialized = pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prvCheckMutexInit(lv_mutex_t * pxMutex)
|
||||||
{
|
{
|
||||||
/* Check if the mutex needs to be initialized. */
|
/* Check if the mutex needs to be initialized. */
|
||||||
if(pxMutex->xIsInitialized == pdFALSE) {
|
if(pxMutex->xIsInitialized == pdFALSE) {
|
||||||
@ -348,16 +340,7 @@ static void prvInitializeMutex(lv_mutex_t * pxMutex)
|
|||||||
* initialized while this function was waiting to enter the critical
|
* initialized while this function was waiting to enter the critical
|
||||||
* section. */
|
* section. */
|
||||||
if(pxMutex->xIsInitialized == pdFALSE) {
|
if(pxMutex->xIsInitialized == pdFALSE) {
|
||||||
pxMutex->xMutex = xSemaphoreCreateMutex();
|
prvMutexInit(pxMutex);
|
||||||
|
|
||||||
/* Ensure that the FreeRTOS mutex was successfully created. */
|
|
||||||
if(pxMutex->xMutex == NULL) {
|
|
||||||
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Mutex successfully created. */
|
|
||||||
pxMutex->xIsInitialized = pdTRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit the critical section. */
|
/* Exit the critical section. */
|
||||||
@ -366,7 +349,33 @@ static void prvInitializeMutex(lv_mutex_t * pxMutex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !USE_FREERTOS_TASK_NOTIFY
|
#if !USE_FREERTOS_TASK_NOTIFY
|
||||||
static void prvInitializeCond(lv_thread_sync_t * pxCond)
|
static void prvCondInit(lv_thread_sync_t * pxCond)
|
||||||
|
{
|
||||||
|
pxCond->xCondWaitSemaphore = xSemaphoreCreateCounting(ulMAX_COUNT, 0U);
|
||||||
|
|
||||||
|
/* Ensure that the FreeRTOS semaphore was successfully created. */
|
||||||
|
if(pxCond->xCondWaitSemaphore == NULL) {
|
||||||
|
LV_LOG_ERROR("xSemaphoreCreateCounting failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pxCond->xSyncMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
|
/* Ensure that the FreeRTOS mutex was successfully created. */
|
||||||
|
if(pxCond->xSyncMutex == NULL) {
|
||||||
|
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
||||||
|
/* Cleanup. */
|
||||||
|
vSemaphoreDelete(pxCond->xCondWaitSemaphore);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Condition variable successfully created. */
|
||||||
|
pxCond->ulWaitingThreads = 0;
|
||||||
|
pxCond->xSyncSignal = pdFALSE;
|
||||||
|
pxCond->xIsInitialized = pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prvCheckCondInit(lv_thread_sync_t * pxCond)
|
||||||
{
|
{
|
||||||
BaseType_t xSemCreateStatus = pdTRUE;
|
BaseType_t xSemCreateStatus = pdTRUE;
|
||||||
|
|
||||||
@ -376,28 +385,13 @@ static void prvInitializeCond(lv_thread_sync_t * pxCond)
|
|||||||
* threads from initializing it at the same time. */
|
* threads from initializing it at the same time. */
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
|
|
||||||
pxCond->xCondWaitSemaphore = xSemaphoreCreateCounting(ulMAX_COUNT, 0U);
|
/* Check again that the condition is still uninitialized, i.e. it wasn't
|
||||||
|
* initialized while this function was waiting to enter the critical
|
||||||
/* Ensure that the FreeRTOS semapahore was successfully created. */
|
* section. */
|
||||||
if(pxCond->xCondWaitSemaphore == NULL) {
|
if(pxCond->xIsInitialized == pdFALSE) {
|
||||||
LV_LOG_ERROR("xSemaphoreCreateCounting failed!");
|
prvCondInit(pxCond);
|
||||||
xSemCreateStatus = pdFALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pxCond->xSyncMutex = xSemaphoreCreateMutex();
|
|
||||||
|
|
||||||
/* Ensure that the FreeRTOS mutex was successfully created. */
|
|
||||||
if(pxCond->xSyncMutex == NULL) {
|
|
||||||
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
|
|
||||||
xSemCreateStatus = pdFALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(xSemCreateStatus != pdFALSE) {
|
|
||||||
/* Condition variable successfully created. */
|
|
||||||
pxCond->ulWaitingThreads = 0;
|
|
||||||
pxCond->xSyncSignal = pdFALSE;
|
|
||||||
pxCond->xIsInitialized = pdTRUE;
|
|
||||||
}
|
|
||||||
/* Exit the critical section. */
|
/* Exit the critical section. */
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user