ble_mesh: Split mesh mutex into a separate file

This commit is contained in:
lly
2020-03-30 18:24:59 +08:00
parent 7db10be193
commit ac51ec11ec
11 changed files with 265 additions and 210 deletions

View File

@@ -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);
}
}