diff options
author | Ledion Daja <ledion.daja@arm.com> | 2022-04-05 15:04:11 +0200 |
---|---|---|
committer | Ledion Daja <ledion.daja@arm.com> | 2022-05-04 15:37:50 +0200 |
commit | 60c5737c37471b4e34f1ffc085e8b12e2a7c6866 (patch) | |
tree | 8ea4ef8763c2f10508b02b859a9ad0723e46a1ed /applications/message_handler/main.cpp | |
parent | 134c39e5e95725d2f79ed2b8cf215d336cc46cd0 (diff) | |
download | ethos-u-core-platform-60c5737c37471b4e34f1ffc085e8b12e2a7c6866.tar.gz |
Change return value of mutex and semaphore handling functions
Changed mutex lock/unlock and semaphore take/give functions to return
an int value instead of void. In addition changed FreeRTOS and
message_handler applications (also FreeRTOS-based) to ignore failure
of xSemaphoreGive on binary semaphores, as it does not affect the
correctness of such applications.
Change-Id: I023c62dc8971488107679f6dd7a5967dec0380a8
Diffstat (limited to 'applications/message_handler/main.cpp')
-rw-r--r-- | applications/message_handler/main.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/applications/message_handler/main.cpp b/applications/message_handler/main.cpp index d478ae6..dde5dc5 100644 --- a/applications/message_handler/main.cpp +++ b/applications/message_handler/main.cpp @@ -96,28 +96,53 @@ void *ethosu_mutex_create(void) { return xSemaphoreCreateMutex(); } -void ethosu_mutex_lock(void *mutex) { +int ethosu_mutex_lock(void *mutex) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); - xSemaphoreTake(handle, portMAX_DELAY); + if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { + printf("Error: Failed to lock mutex.\n"); + return -1; + } + return 0; } -void ethosu_mutex_unlock(void *mutex) { +int ethosu_mutex_unlock(void *mutex) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); - xSemaphoreGive(handle); + if (xSemaphoreGive(handle) != pdTRUE) { + printf("Error: Failed to unlock mutex.\n"); + return -1; + } + return 0; } void *ethosu_semaphore_create(void) { return xSemaphoreCreateBinary(); } -void ethosu_semaphore_take(void *sem) { +int ethosu_semaphore_take(void *sem) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); - xSemaphoreTake(handle, portMAX_DELAY); + if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { + printf("Error: Failed to take semaphore.\n"); + return -1; + } + return 0; } -void ethosu_semaphore_give(void *sem) { +int ethosu_semaphore_give(void *sem) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); - xSemaphoreGiveFromISR(handle, NULL); + if (xPortIsInsideInterrupt()) { + if (xSemaphoreGiveFromISR(handle, NULL) != pdTRUE) { + printf("Error: Failed to give semaphore from ISR.\n"); + return -1; + } + } else { + /* A FreeRTOS binary semaphore is fundamentally a queue that can only hold one item. If the queue is full, + * xSemaphoreGive will return a pdFALSE value. Ignoring the return value in here, as a semaphore give failure + * does not affect the application correctness. */ + if (xSemaphoreGive(handle) != pdTRUE) { + // do nothing + } + } + return 0; } } |