ringlogger: document races

This commit is contained in:
Jason A. Donenfeld 2019-03-18 12:49:25 -06:00
parent 2a7dcac258
commit 2e86e5ac35
1 changed files with 3 additions and 0 deletions

View File

@ -42,11 +42,14 @@ void write_msg_to_log(struct log *log, const char *tag, const char *msg)
struct log_line *line;
struct timespec ts;
// Race: This isn't synchronized with the fetch_add below, so items might be slightly out of order.
clock_gettime(CLOCK_REALTIME, &ts);
// Race: More than MAX_LINES writers and this will clash.
index = atomic_fetch_add(&log->next_index, 1);
line = &log->lines[index % MAX_LINES];
// Race: Before this line executes, we'll display old data after new data.
atomic_store(&line->time_ns, 0);
memset(line->line, 0, MAX_LOG_LINE_LENGTH);