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
+7 -7
View File
@@ -175,9 +175,9 @@ public:
*
* This is used in the case of multi_pub/sub to check if it's valid to advertise
* and publish to this node or if another node should be tried. */
bool is_advertised() const { return _advertised; }
bool is_advertised() const { return _advertised.load(); }
void mark_as_advertised() { _advertised = true; }
void mark_as_advertised() { _advertised.store(true); }
/**
* Print statistics
@@ -224,10 +224,10 @@ public:
*/
bool copy(void *dst, unsigned &generation)
{
if ((dst != nullptr) && (_data != nullptr)) {
if ((dst != nullptr) && (_data.load() != nullptr)) {
if (_meta->o_queue == 1) {
ATOMIC_ENTER;
memcpy(dst, _data, _meta->o_size);
memcpy(dst, _data.load(), _meta->o_size);
generation = _generation.load();
ATOMIC_LEAVE;
return true;
@@ -249,7 +249,7 @@ public:
generation = current_generation - _meta->o_queue;
}
memcpy(dst, _data + (_meta->o_size * (generation % _meta->o_queue)), _meta->o_size);
memcpy(dst, _data.load() + (_meta->o_size * (generation % _meta->o_queue)), _meta->o_size);
ATOMIC_LEAVE;
++generation;
@@ -279,13 +279,13 @@ private:
const orb_metadata *_meta; /**< object metadata information */
uint8_t *_data{nullptr}; /**< allocated object buffer */
px4::atomic<uint8_t *> _data{nullptr}; /**< allocated object buffer */
bool _data_valid{false}; /**< At least one valid data */
px4::atomic<unsigned> _generation{0}; /**< object generation count */
List<uORB::SubscriptionCallback *> _callbacks;
const uint8_t _instance; /**< orb multi instance identifier */
bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
px4::atomic_bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
int8_t _subscriber_count{0};