aos: Refactor lockless_queue ownership into a class
This sets us up to make it more robust with a safer API. Our end goal
is to more reliably detect thread deaths.
Change-Id: I00fad59a4d77eec31f0f51c85834b0892d2d2462
Co-authored-By: Austin Schuh <austin.schuh@bluerivertech.com>
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/ipc_lib/robust_ownership_tracker.cc b/aos/ipc_lib/robust_ownership_tracker.cc
new file mode 100644
index 0000000..3b6d32a
--- /dev/null
+++ b/aos/ipc_lib/robust_ownership_tracker.cc
@@ -0,0 +1,29 @@
+#include "aos/ipc_lib/robust_ownership_tracker.h"
+
+#include "aos/ipc_lib/lockless_queue.h"
+
+namespace aos {
+namespace ipc_lib {
+
+bool RobustOwnershipTracker::PretendThatOwnerIsDeadForTesting(pid_t died_tid) {
+ return ipc_lib::PretendThatOwnerIsDeadForTesting(&mutex_, died_tid);
+}
+
+::std::string RobustOwnershipTracker::DebugString() const {
+ ::std::stringstream s;
+ s << "{.tid=aos_mutex(" << ::std::hex << mutex_.futex;
+
+ if (mutex_.futex != 0) {
+ s << ":";
+ if (mutex_.futex & FUTEX_OWNER_DIED) {
+ s << "FUTEX_OWNER_DIED|";
+ }
+ s << "tid=" << (mutex_.futex & FUTEX_TID_MASK);
+ }
+
+ s << "),}";
+ return s.str();
+}
+
+} // namespace ipc_lib
+} // namespace aos