forked from Archive/PX4-Autopilot
px4_atomic: use volatile hack for Snappy
It looks like the atomic builtins are not available using QuRT and the Hexagon toolchain, so our best bet is to use `volatile` for the atomics.
This commit is contained in:
parent
e6621bf7fb
commit
0a978f51e6
|
@ -80,7 +80,11 @@ public:
|
||||||
*/
|
*/
|
||||||
inline T load() const
|
inline T load() const
|
||||||
{
|
{
|
||||||
|
#ifdef __PX4_QURT
|
||||||
|
return _value;
|
||||||
|
#else
|
||||||
return __atomic_load_n(&_value, __ATOMIC_SEQ_CST);
|
return __atomic_load_n(&_value, __ATOMIC_SEQ_CST);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +92,11 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void store(T value)
|
inline void store(T value)
|
||||||
{
|
{
|
||||||
|
#ifdef __PX4_QURT
|
||||||
|
_value = value;
|
||||||
|
#else
|
||||||
__atomic_store(&_value, &value, __ATOMIC_SEQ_CST);
|
__atomic_store(&_value, &value, __ATOMIC_SEQ_CST);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +167,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef __PX4_QURT
|
||||||
|
// It seems that __atomic_store and __atomic_load are not supported on Qurt,
|
||||||
|
// so the best that we can do is to use volatile.
|
||||||
|
volatile T _value;
|
||||||
|
#else
|
||||||
T _value;
|
T _value;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
using atomic_int = atomic<int>;
|
using atomic_int = atomic<int>;
|
||||||
|
|
Loading…
Reference in New Issue