diff options
-rw-r--r-- | base/ref_counted.cc | 7 | ||||
-rw-r--r-- | base/ref_counted.h | 3 | ||||
-rw-r--r-- | base/thread_collision_warner.h | 2 | ||||
-rw-r--r-- | base/thread_collision_warner_unittest.cc | 38 |
4 files changed, 43 insertions, 7 deletions
diff --git a/base/ref_counted.cc b/base/ref_counted.cc index dfb3698..597c92c 100644 --- a/base/ref_counted.cc +++ b/base/ref_counted.cc @@ -5,6 +5,7 @@ #include "base/ref_counted.h" #include "base/logging.h" +#include "base/thread_collision_warner.h" namespace base { @@ -23,6 +24,9 @@ RefCountedBase::~RefCountedBase() { } void RefCountedBase::AddRef() { + // TODO(maruel): Add back once it doesn't assert 500 times/sec. + // Current thread books the critical section "AddRelease" without release it. + // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); #ifndef NDEBUG DCHECK(!in_dtor_); #endif @@ -30,6 +34,9 @@ void RefCountedBase::AddRef() { } bool RefCountedBase::Release() { + // TODO(maruel): Add back once it doesn't assert 500 times/sec. + // Current thread books the critical section "AddRelease" without release it. + // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); #ifndef NDEBUG DCHECK(!in_dtor_); #endif diff --git a/base/ref_counted.h b/base/ref_counted.h index 2268808..853fa90 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -7,6 +7,7 @@ #include "base/atomic_ref_count.h" #include "base/basictypes.h" +#include "base/thread_collision_warner.h" namespace base { @@ -28,6 +29,8 @@ class RefCountedBase { bool in_dtor_; #endif + DFAKE_MUTEX(add_release_); + DISALLOW_COPY_AND_ASSIGN(RefCountedBase); }; diff --git a/base/thread_collision_warner.h b/base/thread_collision_warner.h index 6545451..4a9481d 100644 --- a/base/thread_collision_warner.h +++ b/base/thread_collision_warner.h @@ -97,7 +97,7 @@ // }; -#if !defined(NDEBUG) || defined(UNIT_TEST) +#if !defined(NDEBUG) // Defines a class member that acts like a mutex. It is used only as a // verification tool. diff --git a/base/thread_collision_warner_unittest.cc b/base/thread_collision_warner_unittest.cc index 7994d13..93a74e5 100644 --- a/base/thread_collision_warner_unittest.cc +++ b/base/thread_collision_warner_unittest.cc @@ -89,15 +89,21 @@ TEST(ThreadCollisionTest, ScopedBookCriticalSection) { { // Pin section. DFAKE_SCOPED_LOCK(warner); EXPECT_FALSE(local_reporter->fail_state()); - { // Pin section again (not allowed by DFAKE_SCOPED_LOCK) + { + // Pin section again (not allowed by DFAKE_SCOPED_LOCK) DFAKE_SCOPED_LOCK(warner); +#if !defined(NDEBUG) EXPECT_TRUE(local_reporter->fail_state()); +#else + EXPECT_FALSE(local_reporter->fail_state()); +#endif // Reset the status of warner for further tests. local_reporter->reset(); } // Unpin section. } // Unpin section. - { // Pin section. + { + // Pin section. DFAKE_SCOPED_LOCK(warner); EXPECT_FALSE(local_reporter->fail_state()); } // Unpin section. @@ -107,7 +113,10 @@ TEST(ThreadCollisionTest, MTBookCriticalSectionTest) { class NonThreadSafeQueue { public: explicit NonThreadSafeQueue(base::AsserterBase* asserter) - : push_pop_(asserter) { } +#if !defined(NDEBUG) + : push_pop_(asserter) +#endif + { } void push(int value) { DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); @@ -154,7 +163,11 @@ TEST(ThreadCollisionTest, MTBookCriticalSectionTest) { thread_a.Join(); thread_b.Join(); +#if !defined(NDEBUG) EXPECT_TRUE(local_reporter->fail_state()); +#else + EXPECT_FALSE(local_reporter->fail_state()); +#endif } TEST(ThreadCollisionTest, MTScopedBookCriticalSectionTest) { @@ -163,7 +176,10 @@ TEST(ThreadCollisionTest, MTScopedBookCriticalSectionTest) { class NonThreadSafeQueue { public: explicit NonThreadSafeQueue(base::AsserterBase* asserter) - : push_pop_(asserter) { } +#if !defined(NDEBUG) + : push_pop_(asserter) +#endif + { } void push(int value) { DFAKE_SCOPED_LOCK(push_pop_); @@ -211,7 +227,11 @@ TEST(ThreadCollisionTest, MTScopedBookCriticalSectionTest) { thread_a.Join(); thread_b.Join(); +#if !defined(NDEBUG) EXPECT_TRUE(local_reporter->fail_state()); +#else + EXPECT_FALSE(local_reporter->fail_state()); +#endif } TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { @@ -220,7 +240,10 @@ TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { class NonThreadSafeQueue { public: explicit NonThreadSafeQueue(base::AsserterBase* asserter) - : push_pop_(asserter) { } +#if !defined(NDEBUG) + : push_pop_(asserter) +#endif + { } void push(int value) { DFAKE_SCOPED_LOCK(push_pop_); @@ -288,7 +311,10 @@ TEST(ThreadCollisionTest, MTSynchedScopedRecursiveBookCriticalSectionTest) { class NonThreadSafeQueue { public: explicit NonThreadSafeQueue(base::AsserterBase* asserter) - : push_pop_(asserter) { } +#if !defined(NDEBUG) + : push_pop_(asserter) +#endif + { } void push(int) { DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |