mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 07:43:35 +08:00
uORB: fix TSAN issues using atomics
This commit is contained in:
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user