Skip to content

Commit c19eed0

Browse files
jplexergmarull
authored andcommitted
fw/services/hrm_manager: fix assert in prv_system_task_hrm_handler
Check if data is available in the circular buffer before attempting to read in prv_system_task_hrm_handler(). This prevents an assertion failure when system task callbacks are queued without corresponding events in the buffer, which can occur during high system load such as voice dictation session startup. The race condition occurs when: - prv_event_put() queues an event and calls system_task_add_callback() - Multiple callbacks may be queued rapidly during system load - One callback processes and consumes the event - Another callback runs but finds the buffer empty Instead of asserting and crashing, we now log a warning and return gracefully. HRM functionality continues normally as new events arrive. Signed-off-by: Joshua Jun <joshuajun@proton.me>
1 parent 9605902 commit c19eed0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/fw/services/common/hrm/hrm_manager.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ static void prv_system_task_hrm_handler(void *context) {
369369
time_t utc_now = rtc_get_time();
370370

371371
mutex_lock_recursive(s_manager_state.lock);
372+
373+
// Check if there's data available in the circular buffer before attempting to read
374+
const uint16_t available_bytes =
375+
circular_buffer_get_read_space_remaining(&s_manager_state.system_task_event_buffer);
376+
if (available_bytes < sizeof(PebbleHRMEvent)) {
377+
// No event available to read - this can happen if system task callbacks are queued
378+
// without corresponding events, or during concurrent access.
379+
PBL_LOG(LOG_LEVEL_WARNING, "HRM: system task handler called with no event in buffer "
380+
"(available=%u, needed=%u)", available_bytes, sizeof(PebbleHRMEvent));
381+
mutex_unlock_recursive(s_manager_state.lock);
382+
return;
383+
}
384+
372385
PebbleHRMEvent event;
373386
prv_read_event_from_buffer_and_consume(&s_manager_state.system_task_event_buffer, &event);
374387

0 commit comments

Comments
 (0)