uORB: fix TSAN issues using atomics

This commit is contained in:
Julian Oes
2026-02-18 12:43:02 +13:00
parent 91e25df7c4
commit 22a32eaa55
13 changed files with 92 additions and 75 deletions
+12 -5
View File
@@ -41,6 +41,7 @@
#include <uORB/uORB.h>
#include <uORB/topics/uORBTopics.hpp>
#include <px4_platform_common/atomic.h>
#include <px4_platform_common/defines.h>
#include <lib/mathlib/mathlib.h>
@@ -131,7 +132,7 @@ public:
bool updated()
{
if (subscribe()) {
return Manager::updates_available(_node, _last_generation);
return Manager::updates_available(_node, _last_generation.load());
}
return false;
@@ -144,7 +145,10 @@ public:
bool update(void *dst)
{
if (subscribe()) {
return Manager::orb_data_copy(_node, dst, _last_generation, true);
unsigned gen = _last_generation.load();
bool ret = Manager::orb_data_copy(_node, dst, gen, true);
_last_generation.store(gen);
return ret;
}
return false;
@@ -157,7 +161,10 @@ public:
bool copy(void *dst)
{
if (subscribe()) {
return Manager::orb_data_copy(_node, dst, _last_generation, false);
unsigned gen = _last_generation.load();
bool ret = Manager::orb_data_copy(_node, dst, gen, false);
_last_generation.store(gen);
return ret;
}
return false;
@@ -170,7 +177,7 @@ public:
bool ChangeInstance(uint8_t instance);
uint8_t get_instance() const { return _instance; }
unsigned get_last_generation() const { return _last_generation; }
unsigned get_last_generation() const { return _last_generation.load(); }
orb_id_t get_topic() const { return get_orb_meta(_orb_id); }
ORB_ID orb_id() const { return _orb_id; }
@@ -184,7 +191,7 @@ protected:
void *_node{nullptr};
unsigned _last_generation{0}; /**< last generation the subscriber has seen */
px4::atomic<unsigned> _last_generation{0}; /**< last generation the subscriber has seen */
ORB_ID _orb_id{ORB_ID::INVALID};
uint8_t _instance{0};