Mutex tidy up.
Condition variable names needn't be strings - the use was leading to valgrind
warnings.
Don't fail AssertSharedHeld when self isn't known.
Allow gtest thread chance to merge to avoid memory leak.
Make barrier test log output more human readable.
Change-Id: If1923c69a2965d933036c496dc5b1d64ec887db2
diff --git a/src/barrier_test.cc b/src/barrier_test.cc
index bb7bcb3..093ba35 100644
--- a/src/barrier_test.cc
+++ b/src/barrier_test.cc
@@ -37,14 +37,14 @@
}
void Run(Thread* self) {
- LOG(INFO) << "Before barrier 1 " << self;
+ LOG(INFO) << "Before barrier 1 " << *self;
++*count1_;
barrier_->Wait(self);
++*count2_;
- LOG(INFO) << "Before barrier 2 " << self;
+ LOG(INFO) << "Before barrier 2 " << *self;
barrier_->Wait(self);
++*count3_;
- LOG(INFO) << "After barrier 2 " << self;
+ LOG(INFO) << "After barrier 2 " << *self;
}
virtual void Finalize() {
diff --git a/src/base/mutex.cc b/src/base/mutex.cc
index 912e7fd..86356a9 100644
--- a/src/base/mutex.cc
+++ b/src/base/mutex.cc
@@ -690,7 +690,7 @@
return os;
}
-ConditionVariable::ConditionVariable(const std::string& name, Mutex& guard)
+ConditionVariable::ConditionVariable(const char* name, Mutex& guard)
: name_(name), guard_(guard) {
#if ART_USE_FUTEXES
sequence_ = 0;
diff --git a/src/base/mutex.h b/src/base/mutex.h
index b4e0536..48c8585 100644
--- a/src/base/mutex.h
+++ b/src/base/mutex.h
@@ -258,7 +258,8 @@
// Assert the current thread has shared access to the ReaderWriterMutex.
void AssertSharedHeld(const Thread* self) {
if (kDebugLocking) {
- CHECK(IsSharedHeld(self)) << *this;
+ // TODO: we can only assert this well when self != NULL.
+ CHECK(IsSharedHeld(self) || self == NULL) << *this;
}
}
void AssertReaderHeld(const Thread* self) { AssertSharedHeld(self); }
@@ -297,7 +298,7 @@
// (Signal) or all at once (Broadcast).
class ConditionVariable {
public:
- explicit ConditionVariable(const std::string& name, Mutex& mutex);
+ explicit ConditionVariable(const char* name, Mutex& mutex);
~ConditionVariable();
void Broadcast(Thread* self);
@@ -308,7 +309,7 @@
void TimedWait(Thread* self, int64_t ms, int32_t ns) NO_THREAD_SAFETY_ANALYSIS;
private:
- std::string name_;
+ const char* const name_;
// The Mutex being used by waiters. It is an error to mix condition variables between different
// Mutexes.
Mutex& guard_;
diff --git a/src/base/mutex_test.cc b/src/base/mutex_test.cc
index 0b0f2c9..1af8e0a 100644
--- a/src/base/mutex_test.cc
+++ b/src/base/mutex_test.cc
@@ -126,6 +126,7 @@
state.mu.Unlock(Thread::Current());
state.mu.Unlock(Thread::Current());
+ EXPECT_EQ(pthread_join(pthread, NULL), 0);
}
// This ensures we don't hang when waiting on a recursively locked mutex,