mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
openthread: Add check for lock acquire and release
This commit is contained in:
@ -5,8 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "esp_openthread_lock.h"
|
#include "esp_openthread_lock.h"
|
||||||
|
#include "esp_openthread_common_macro.h"
|
||||||
|
|
||||||
|
#include "esp_check.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
@ -15,6 +18,8 @@ static SemaphoreHandle_t s_openthread_mutex = NULL;
|
|||||||
|
|
||||||
bool esp_openthread_lock_acquire(TickType_t block_ticks)
|
bool esp_openthread_lock_acquire(TickType_t block_ticks)
|
||||||
{
|
{
|
||||||
|
ESP_RETURN_ON_FALSE(s_openthread_mutex && s_openthread_task_mutex, false, OT_PLAT_LOG_TAG,
|
||||||
|
"Failed to acquire the lock because the mutex is not ready");
|
||||||
BaseType_t ret = xSemaphoreTakeRecursive(s_openthread_mutex, block_ticks) &&
|
BaseType_t ret = xSemaphoreTakeRecursive(s_openthread_mutex, block_ticks) &&
|
||||||
xSemaphoreTakeRecursive(s_openthread_task_mutex, block_ticks);
|
xSemaphoreTakeRecursive(s_openthread_task_mutex, block_ticks);
|
||||||
return (ret == pdTRUE);
|
return (ret == pdTRUE);
|
||||||
@ -22,18 +27,24 @@ bool esp_openthread_lock_acquire(TickType_t block_ticks)
|
|||||||
|
|
||||||
void esp_openthread_lock_release(void)
|
void esp_openthread_lock_release(void)
|
||||||
{
|
{
|
||||||
|
ESP_RETURN_ON_FALSE(s_openthread_mutex && s_openthread_task_mutex, , OT_PLAT_LOG_TAG,
|
||||||
|
"Failed to release the lock because the mutex is not ready");
|
||||||
xSemaphoreGiveRecursive(s_openthread_task_mutex);
|
xSemaphoreGiveRecursive(s_openthread_task_mutex);
|
||||||
xSemaphoreGiveRecursive(s_openthread_mutex);
|
xSemaphoreGiveRecursive(s_openthread_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool esp_openthread_task_switching_lock_acquire(TickType_t block_ticks)
|
bool esp_openthread_task_switching_lock_acquire(TickType_t block_ticks)
|
||||||
{
|
{
|
||||||
|
ESP_RETURN_ON_FALSE(s_openthread_task_mutex, false, OT_PLAT_LOG_TAG,
|
||||||
|
"Failed to acquire the lock because the mutex is not ready");
|
||||||
BaseType_t ret = xSemaphoreTakeRecursive(s_openthread_task_mutex, block_ticks);
|
BaseType_t ret = xSemaphoreTakeRecursive(s_openthread_task_mutex, block_ticks);
|
||||||
return (ret == pdTRUE);
|
return (ret == pdTRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_openthread_task_switching_lock_release(void)
|
void esp_openthread_task_switching_lock_release(void)
|
||||||
{
|
{
|
||||||
|
ESP_RETURN_ON_FALSE(s_openthread_task_mutex, , OT_PLAT_LOG_TAG,
|
||||||
|
"Failed to release the lock because the mutex is not ready");
|
||||||
xSemaphoreGiveRecursive(s_openthread_task_mutex);
|
xSemaphoreGiveRecursive(s_openthread_task_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user