mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-14 22:16:46 +00:00
ble_mesh: Split mesh mutex into a separate file
This commit is contained in:
@@ -65,62 +65,3 @@ u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send)
|
||||
|
||||
return client->msg_role;
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
mutex->buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(mutex->buffer, "%s, Failed to create queue buffer", __func__);
|
||||
mutex->mutex = xSemaphoreCreateMutexStatic(mutex->buffer);
|
||||
__ASSERT(mutex->mutex, "%s, Failed to create static mutex", __func__);
|
||||
#else
|
||||
mutex->mutex = xSemaphoreCreateMutex();
|
||||
__ASSERT(mutex->mutex, "%s, Failed to create mutex", __func__);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
vSemaphoreDelete(mutex->mutex);
|
||||
mutex->mutex = NULL;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
heap_caps_free(mutex->buffer);
|
||||
mutex->buffer = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
xSemaphoreTake(mutex->mutex, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
xSemaphoreGive(mutex->mutex);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user