ipmi_handler: make sequence number to be atomic
IpmiHandler::sequence needs to be thread safe or atomic
otherwise thread sanitizer will complaint about it
Change-Id: Idde90599e85be5a64a328fbd420ecfa1a7f960cf
Signed-off-by: Anh Phan <anhphan@google.com>
diff --git a/src/ipmiblob/ipmi_handler.cpp b/src/ipmiblob/ipmi_handler.cpp
index 81a70ca..90d3510 100644
--- a/src/ipmiblob/ipmi_handler.cpp
+++ b/src/ipmiblob/ipmi_handler.cpp
@@ -92,7 +92,7 @@
ipmi_req request{};
request.addr = reinterpret_cast<unsigned char*>(&systemAddress);
request.addr_len = sizeof(systemAddress);
- request.msgid = sequence++;
+ request.msgid = sequence.fetch_add(1, std::memory_order_relaxed);
request.msg.data = reinterpret_cast<unsigned char*>(data.data());
request.msg.data_len = data.size();
request.msg.netfn = netfn;
diff --git a/src/ipmiblob/ipmi_handler.hpp b/src/ipmiblob/ipmi_handler.hpp
index e98231d..fedc068 100644
--- a/src/ipmiblob/ipmi_handler.hpp
+++ b/src/ipmiblob/ipmi_handler.hpp
@@ -3,6 +3,7 @@
#include "internal/sys.hpp"
#include "ipmi_interface.hpp"
+#include <atomic>
#include <memory>
#include <vector>
@@ -47,7 +48,7 @@
*/
int fd = -1;
/* The last IPMI sequence number we used. */
- int sequence = 0;
+ std::atomic_int sequence = 0;
};
} // namespace ipmiblob