mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-24 15:27:41 +08:00
_interval_us and _last_update are read in SubscriptionCallbackWorkItem::call() (and SubscriptionBlocking::call()) on the publishing thread, while the subscriber sets them - e.g. from mixer_module's setMaxTopicUpdateRate() on a reconfigure. That is a genuine cross-thread access that ThreadSanitizer flags. Instead of making these fields atomic in the base SubscriptionInterval - which is used single-threaded by 100+ subscriptions - parameterize the class on whether the interval / last-update storage is atomic and expose two aliases: SubscriptionInterval plain, single-threaded (the common case) SubscriptionIntervalAtomic atomic, for callback subscriptions SubscriptionCallback - and hence all callback subscriptions (SubscriptionCallbackWorkItem, SubscriptionBlocking, CallbackHandler) - uses the atomic variant; every other subscription stays plain with no synchronization overhead. The updated()/update()/copy() bodies stay out-of-line with explicit instantiation of both variants, so they are not inlined at every call site (flash size).