Actually manage memory in the old-style AOS logging
LeakSanitizer should be happy with it now. It's also still just as
thread-safe.
Change-Id: Id09a0349657cf4f719267b053f0ea3d8ec366256
diff --git a/aos/stl_mutex/BUILD b/aos/stl_mutex/BUILD
index 06599e3..51229d4 100644
--- a/aos/stl_mutex/BUILD
+++ b/aos/stl_mutex/BUILD
@@ -7,7 +7,7 @@
],
deps = [
"//aos/ipc_lib:aos_sync",
- "//aos/logging",
+ "@com_github_google_glog//:glog",
],
)
@@ -20,6 +20,5 @@
":stl_mutex",
"//aos:die",
"//aos/testing:googletest",
- "//aos/testing:test_logging",
],
)
diff --git a/aos/stl_mutex/stl_mutex.h b/aos/stl_mutex/stl_mutex.h
index 4e14557..86a5988 100644
--- a/aos/stl_mutex/stl_mutex.h
+++ b/aos/stl_mutex/stl_mutex.h
@@ -4,9 +4,8 @@
#include <mutex>
#include "aos/ipc_lib/aos_sync.h"
-#include "aos/logging/logging.h"
-#include "aos/type_traits/type_traits.h"
#include "aos/macros.h"
+#include "glog/logging.h"
namespace aos {
@@ -31,7 +30,7 @@
owner_died_ = true;
break;
default:
- AOS_LOG(FATAL, "mutex_grab(%p) failed with %d\n", &native_handle_, ret);
+ LOG(FATAL) << "mutex_grab(" << &native_handle_ << ") failed: " << ret;
}
}
@@ -46,13 +45,13 @@
case 4:
return false;
default:
- AOS_LOG(FATAL, "mutex_trylock(%p) failed with %d\n", &native_handle_,
- ret);
+ LOG(FATAL) << "mutex_trylock(" << &native_handle_
+ << ") failed: " << ret;
}
}
void unlock() {
- AOS_CHECK(!owner_died_);
+ CHECK(!owner_died_);
mutex_unlock(&native_handle_);
}
@@ -84,20 +83,20 @@
void lock() {
if (mutex_islocked(mutex_.native_handle())) {
- AOS_CHECK(!owner_died());
+ CHECK(!owner_died());
++recursive_locks_;
} else {
mutex_.lock();
if (mutex_.owner_died()) {
recursive_locks_ = 0;
} else {
- AOS_CHECK_EQ(0, recursive_locks_);
+ CHECK_EQ(0, recursive_locks_);
}
}
}
bool try_lock() {
if (mutex_islocked(mutex_.native_handle())) {
- AOS_CHECK(!owner_died());
+ CHECK(!owner_died());
++recursive_locks_;
return true;
} else {
@@ -105,7 +104,7 @@
if (mutex_.owner_died()) {
recursive_locks_ = 0;
} else {
- AOS_CHECK_EQ(0, recursive_locks_);
+ CHECK_EQ(0, recursive_locks_);
}
return true;
} else {
diff --git a/aos/stl_mutex/stl_mutex_test.cc b/aos/stl_mutex/stl_mutex_test.cc
index 0fd052a..5e88c56 100644
--- a/aos/stl_mutex/stl_mutex_test.cc
+++ b/aos/stl_mutex/stl_mutex_test.cc
@@ -2,7 +2,6 @@
#include "gtest/gtest.h"
-#include "aos/testing/test_logging.h"
#include "aos/die.h"
namespace aos {
@@ -10,10 +9,7 @@
class StlMutexDeathTest : public ::testing::Test {
protected:
- void SetUp() override {
- ::aos::testing::EnableTestLogging();
- SetDieTestMode(true);
- }
+ void SetUp() override { SetDieTestMode(true); }
};
typedef StlMutexDeathTest StlRecursiveMutexDeathTest;
@@ -58,7 +54,7 @@
mutex.lock();
ASSERT_TRUE(mutex.try_lock());
mutex.unlock();
- mutex.unlock();
+ mutex.unlock();
}
// Tests that unlocking an unlocked recursive mutex fails.