mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[ntcore] Protobuf/Struct: Use atomic_bool instead of atomic_flag (#5946)
Some older compilers don't have atomic_flag::test().
This commit is contained in:
@@ -212,10 +212,9 @@ class ProtobufPublisher : public Publisher {
|
||||
ProtobufPublisher& operator=(ProtobufPublisher&& rhs) {
|
||||
Publisher::operator=(std::move(rhs));
|
||||
m_msg = std::move(rhs.m_msg);
|
||||
m_schemaPublished.clear();
|
||||
if (rhs.m_schemaPublished.test()) {
|
||||
m_schemaPublished.test_and_set();
|
||||
}
|
||||
m_schemaPublished.store(
|
||||
rhs.m_schemaPublished.load(std::memory_order_relaxed),
|
||||
std::memory_order_relaxed);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -229,7 +228,7 @@ class ProtobufPublisher : public Publisher {
|
||||
wpi::SmallVector<uint8_t, 128> buf;
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddProtobufSchema<T>(m_msg);
|
||||
}
|
||||
m_msg.Pack(buf, value);
|
||||
@@ -248,7 +247,7 @@ class ProtobufPublisher : public Publisher {
|
||||
wpi::SmallVector<uint8_t, 128> buf;
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddProtobufSchema<T>(m_msg);
|
||||
}
|
||||
m_msg.Pack(buf, value);
|
||||
@@ -268,7 +267,7 @@ class ProtobufPublisher : public Publisher {
|
||||
private:
|
||||
wpi::mutex m_mutex;
|
||||
wpi::ProtobufMessage<T> m_msg;
|
||||
std::atomic_flag m_schemaPublished = ATOMIC_FLAG_INIT;
|
||||
std::atomic_bool m_schemaPublished{false};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -238,10 +238,9 @@ class StructArrayPublisher : public Publisher {
|
||||
StructArrayPublisher& operator=(StructArrayPublisher&& rhs) {
|
||||
Publisher::operator=(std::move(rhs));
|
||||
m_buf = std::move(rhs.m_buf);
|
||||
m_schemaPublished.clear();
|
||||
if (rhs.m_schemaPublished.test()) {
|
||||
m_schemaPublished.test_and_set();
|
||||
}
|
||||
m_schemaPublished.store(
|
||||
rhs.m_schemaPublished.load(std::memory_order_relaxed),
|
||||
std::memory_order_relaxed);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -257,7 +256,7 @@ class StructArrayPublisher : public Publisher {
|
||||
std::convertible_to<std::ranges::range_value_t<U>, T>
|
||||
#endif
|
||||
void Set(U&& value, int64_t time = 0) {
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddStructSchema<T>();
|
||||
}
|
||||
m_buf.Write(std::forward<U>(value),
|
||||
@@ -288,7 +287,7 @@ class StructArrayPublisher : public Publisher {
|
||||
std::convertible_to<std::ranges::range_value_t<U>, T>
|
||||
#endif
|
||||
void SetDefault(U&& value) {
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddStructSchema<T>();
|
||||
}
|
||||
m_buf.Write(std::forward<U>(value),
|
||||
@@ -318,7 +317,7 @@ class StructArrayPublisher : public Publisher {
|
||||
|
||||
private:
|
||||
wpi::StructArrayBuffer<T> m_buf;
|
||||
std::atomic_flag m_schemaPublished = ATOMIC_FLAG_INIT;
|
||||
std::atomic_bool m_schemaPublished{false};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,10 +184,9 @@ class StructPublisher : public Publisher {
|
||||
|
||||
StructPublisher& operator=(StructPublisher&& rhs) {
|
||||
Publisher::operator=(std::move(rhs));
|
||||
m_schemaPublished.clear();
|
||||
if (rhs.m_schemaPublished.test()) {
|
||||
m_schemaPublished.test_and_set();
|
||||
}
|
||||
m_schemaPublished.store(
|
||||
rhs.m_schemaPublished.load(std::memory_order_relaxed),
|
||||
std::memory_order_relaxed);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -206,7 +205,7 @@ class StructPublisher : public Publisher {
|
||||
* @param time timestamp; 0 indicates current NT time should be used
|
||||
*/
|
||||
void Set(const T& value, int64_t time = 0) {
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddStructSchema<T>();
|
||||
}
|
||||
uint8_t buf[S::kSize];
|
||||
@@ -222,7 +221,7 @@ class StructPublisher : public Publisher {
|
||||
* @param value value
|
||||
*/
|
||||
void SetDefault(const T& value) {
|
||||
if (!m_schemaPublished.test_and_set()) {
|
||||
if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
|
||||
GetTopic().GetInstance().template AddStructSchema<T>();
|
||||
}
|
||||
uint8_t buf[S::kSize];
|
||||
@@ -240,7 +239,7 @@ class StructPublisher : public Publisher {
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic_flag m_schemaPublished = ATOMIC_FLAG_INIT;
|
||||
std::atomic_bool m_schemaPublished{false};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user