mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-24 16:01:53 +08:00
refactor(uORB): pass generation to SubscriptionCallback::call() to drop the _last_generation atomic
The publisher fires callbacks via SubscriptionCallbackWorkItem::call(), which read the subscriber's _last_generation (and called updated(), which reads it again) to decide whether to schedule the work item. That made the subscriber's read cursor a cross-thread field - publisher reads it while the subscriber writes it in copy() - which TSan flagged and which we had wrapped in an atomic. Instead, hand the publishing node's generation into call() and let the callback keep its own _last_scheduled_generation cursor for the count gate (_required_updates). call() runs under the node lock, so that cursor is only ever touched there and is serialized - no atomic needed, and using the real generation (not a plain counter) means a coalesced/missed call() does not drift the batch. The redundant updated() generation check is dropped (call() only runs right after a publish, so it is always true); the interval gate (_last_update / _interval_us) is kept unchanged. With the publisher no longer reading it, _last_generation reverts to a plain unsigned (subscriber-thread only). Behaviour is unchanged: the count and interval throttles fire at the same rates (verified via work_queue status - gyro_fft 62.5 Hz, flight_mode_manager 50 Hz) and TSan stays clean.
This commit is contained in:
1 parent
bffa69a554
commit
0aa25de0dd
6 files changed
+32
-20
No files matched your search
@@ -196,7 +196,7 @@ uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen)
|
||||
|
||||
// callbacks
|
||||
for (auto item : _callbacks) {
|
||||
item->call();
|
||||
item->call(generation + 1);
|
||||
}
|
||||
|
||||
/* Mark at least one data has been published */
|
||||
|
||||
Reference in new issue
Block a user