Commit Graph
2 Commits
Author SHA1 Message Date
Jash 65b68a188e feat: show the ONVIF subscription status in the monitor editor refs #4191 2026-11-18 14:49:01 +05:30
Isaac ConnorandClaude Opus 5.5 d9a629bcda fix: access SharedData fields as relaxed atomics fixes #5238
zmc's capture, decoder and analysis threads, zms, zmu and the web
interface read and write Monitor::SharedData while the others run, but
its scalar fields were plain members. ThreadSanitizer reported races on
capture_fps, state and analysing, and the action word was worse: zmu
sets bits with |= while zmc clears others with &=, and as plain
read-modify-writes either side could write back a word read before the
other's change and drop its bit.

Wrap every scalar SharedData field in SharedValue<T>, which holds only
the value and does each access as a relaxed __atomic builtin (C++17 has
no std::atomic_ref). Loads and stores keep their meaning, |=, &= and ++
become single atomic operations, and copying one field to another is
deleted because it would not be atomic. The layout Memory.pm and
Monitor.php read is unchanged: the 8-byte fields are aligned to 8 so
clang on i386 doesn't call libatomic, and they already sat on 8-byte
offsets. Values passed through printf-style varargs now call load(),
which -Wformat found. MonitorLink's SharedData pointer drops volatile,
which the atomics replace.

The test checks every field offset against Monitor.php, that the
wrapper reads and writes the plain value, and that setting and clearing
action bits from two threads loses none (plain fields lost 3 to 33 of
200000 rounds here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 08:47:05 -05:00