Called from a log hook — appends a line to the ring buffer (thread-safe) */
| 431 | |
| 432 | /* Called from a log hook — appends a line to the ring buffer (thread-safe) */ |
| 433 | void cbm_ui_log_append(const char *line) { |
| 434 | if (!line) |
| 435 | return; |
| 436 | /* Ensure mutex is initialized (safe for early single-threaded logging |
| 437 | * and concurrent calls via atomic_exchange once-init pattern). */ |
| 438 | cbm_ui_log_init(); |
| 439 | cbm_mutex_lock(&g_log_mutex); |
| 440 | snprintf(g_log_ring[g_log_head], LOG_LINE_MAX, "%s", line); |
| 441 | g_log_head = (g_log_head + 1) % LOG_RING_SIZE; |
| 442 | if (g_log_count < LOG_RING_SIZE) |
| 443 | g_log_count++; |
| 444 | cbm_mutex_unlock(&g_log_mutex); |
| 445 | } |
| 446 | |
| 447 | /* Append a printf-formatted fragment at *pos within a bufsz buffer, never |
| 448 | * advancing *pos past bufsz. snprintf returns the length it WOULD have written, |
no test coverage detected