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:
Julian Oes authored and Ramon Roche committed 2026-07-02 08:42:49 -07:00
1 parent bffa69a554
commit 0aa25de0dd
6 files changed
+32 -20

No files matched your search

+7 -7
View File
@@ -55,7 +55,7 @@ bool Subscription::subscribe()
if (node) {
_node = node;
_last_generation.store(initial_generation);
_last_generation = initial_generation;
return true;
}
}
@@ -70,15 +70,15 @@ void Subscription::unsubscribe()
}
_node = nullptr;
_last_generation.store(0);
_last_generation = 0;
}
bool Subscription::update(void *dst)
{
if (subscribe()) {
unsigned gen = _last_generation.load();
unsigned gen = _last_generation;
bool ret = Manager::orb_data_copy(_node, dst, gen, true);
_last_generation.store(gen);
_last_generation = gen;
return ret;
}
@@ -88,9 +88,9 @@ bool Subscription::update(void *dst)
bool Subscription::copy(void *dst)
{
if (subscribe()) {
unsigned gen = _last_generation.load();
unsigned gen = _last_generation;
bool ret = Manager::orb_data_copy(_node, dst, gen, false);
_last_generation.store(gen);
_last_generation = gen;
return ret;
}
@@ -172,7 +172,7 @@ bool Subscription::advertised()
bool Subscription::updated()
{
if (subscribe()) {
return Manager::updates_available(_node, _last_generation.load());
return Manager::updates_available(_node, _last_generation);
}
return false;