Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21c07da8 authored by VenkatRaghavan V's avatar VenkatRaghavan V Committed by Pavlin Radoslavov
Browse files

Fix the calculation of bta_sys_get_remaining_ticks

Previously, bta_sys_get_remaining_ticks() calculated the remaining
ticks for all the items in the hash map, which is incorrect.
Instead, we need to calculate the remaining ticks only for the queried
item.

Bug: 26110234

Change-Id: Ia867c1d0da15809a643b946f7d8b9143e3882935
parent 6ed3b57e
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -646,22 +646,17 @@ void bta_sys_start_timer(timer_entry_t *p_te, UINT16 type, INT32 timeout_ms) {
  alarm_set(alarm, (period_ms_t)timeout_ms, bta_alarm_cb, p_te);
}

bool hash_iter_ro_cb(hash_map_entry_t *hash_map_entry, void *context)
{
    alarm_t *alarm = (alarm_t *)hash_map_entry->data;
    period_ms_t *p_remaining_ms = (period_ms_t*)context;
    *p_remaining_ms += alarm_get_remaining_ms(alarm);
    return true;
}

UINT32 bta_sys_get_remaining_ticks(timer_entry_t *p_target_te)
{
    period_ms_t remaining_ms = 0;
  pthread_mutex_lock(&bta_alarm_lock);
    // Get the alarm for this p_te
    hash_map_foreach(bta_alarm_hash_map, hash_iter_ro_cb, &remaining_ms);
  alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_target_te);
  pthread_mutex_unlock(&bta_alarm_lock);
    return remaining_ms;
  if (alarm == NULL) {
    LOG_ERROR("%s unable to get alarm", __func__);
    return 0;
  }

  return alarm_get_remaining_ms(alarm);
}