ble_mesh: Check the result of creating timer

This commit is contained in:
lly
2020-05-27 12:26:25 +08:00
committed by bot
parent 3b85d4ef24
commit 6768c2b7a1
4 changed files with 32 additions and 18 deletions

View File

@@ -59,13 +59,13 @@ void bt_mesh_timer_deinit(void)
}
}
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
{
osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__);
return;
return -EINVAL;
}
k_work_init(&work->work, handler);
@@ -74,28 +74,28 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
if (alarm == NULL) {
BT_ERR("%s, Unable to create alarm", __func__);
BT_ERR("%s, Alarm not created", __func__);
bt_mesh_alarm_unlock();
return;
return -EIO;
}
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
BT_ERR("%s Unable to add the timer to hash map.", __func__);
BT_ERR("%s, Alarm not set", __func__);
bt_mesh_alarm_unlock();
return;
return -EIO;
}
}
alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
BT_ERR("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return;
return -ENODEV;
}
// Just init the work timer only, don't start it.
osi_alarm_cancel(alarm);
bt_mesh_alarm_unlock();
return;
return 0;
}
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
@@ -108,7 +108,7 @@ int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return -EINVAL;
}
@@ -130,7 +130,7 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period)
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return -EINVAL;
}
@@ -152,7 +152,7 @@ int k_delayed_work_cancel(struct k_delayed_work *work)
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return -EINVAL;
}
@@ -173,7 +173,7 @@ int k_delayed_work_free(struct k_delayed_work *work)
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) {
BT_WARN("%s Unable to find expected alarm in hash map", __func__);
BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return -EINVAL;
}
@@ -196,7 +196,7 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("%s Unable to find expected alarm in hash map", __func__);
BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock();
return 0;
}