summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 03:13:35 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 03:13:35 +0000
commita571ce8531f2fe4a9ac4b615f75a5b5147459576 (patch)
tree0e44de602d14f08b5ed95c4289d82b961a633772 /base/threading
parent4b7a709e6068cbbfa6ef0c0bbfe1e6a2cb253744 (diff)
downloadchromium_src-a571ce8531f2fe4a9ac4b615f75a5b5147459576.zip
chromium_src-a571ce8531f2fe4a9ac4b615f75a5b5147459576.tar.gz
chromium_src-a571ce8531f2fe4a9ac4b615f75a5b5147459576.tar.bz2
Enable base::NonThreadSafe when DCHECK_ALWAYS_ON is set
Previously base::NonThreadSafe only looked at Debug builds. Also enable it for Release builds when DCHECK_ALWAYS_ON is set (eg: the try bots & waterfall bots) BUG=none TEST=existing Review URL: https://chromiumcodereview.appspot.com/10636044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/non_thread_safe.h25
-rw-r--r--base/threading/non_thread_safe_unittest.cc31
2 files changed, 40 insertions, 16 deletions
diff --git a/base/threading/non_thread_safe.h b/base/threading/non_thread_safe.h
index be30269..a104ae3 100644
--- a/base/threading/non_thread_safe.h
+++ b/base/threading/non_thread_safe.h
@@ -6,13 +6,20 @@
#define BASE_THREADING_NON_THREAD_SAFE_H_
#pragma once
-// Classes deriving from NonThreadSafe may need to supress MSVC warning 4275:
+// Classes deriving from NonThreadSafe may need to suppress MSVC warning 4275:
// non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
// There is a specific macro to do it: NON_EXPORTED_BASE(), defined in
// compiler_specific.h
#include "base/compiler_specific.h"
-#ifndef NDEBUG
+// See comment at top of thread_checker.h
+#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#define ENABLE_NON_THREAD_SAFE 1
+#else
+#define ENABLE_NON_THREAD_SAFE 0
+#endif
+
+#if ENABLE_NON_THREAD_SAFE
#include "base/threading/non_thread_safe_impl.h"
#endif
@@ -54,13 +61,15 @@ class NonThreadSafeDoNothing {
// to have a base::ThreadChecker as a member, rather than inherit from
// NonThreadSafe. For more details about when to choose one over the other, see
// the documentation for base::ThreadChecker.
-//
-// In Release mode, CalledOnValidThread will always return true.
-#ifndef NDEBUG
-typedef NonThreadSafeImpl NonThreadSafe;
+#if ENABLE_NON_THREAD_SAFE
+class NonThreadSafe : public NonThreadSafeImpl {
+};
#else
-typedef NonThreadSafeDoNothing NonThreadSafe;
-#endif // NDEBUG
+class NonThreadSafe : public NonThreadSafeDoNothing {
+};
+#endif // ENABLE_NON_THREAD_SAFE
+
+#undef ENABLE_NON_THREAD_SAFE
} // namespace base
diff --git a/base/threading/non_thread_safe_unittest.cc b/base/threading/non_thread_safe_unittest.cc
index b8376f3..ee31701 100644
--- a/base/threading/non_thread_safe_unittest.cc
+++ b/base/threading/non_thread_safe_unittest.cc
@@ -9,8 +9,18 @@
#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+// Duplicated from base/threading/non_thread_safe.h so that we can be
+// good citizens there and undef the macro.
+#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#define ENABLE_NON_THREAD_SAFE 1
+#else
+#define ENABLE_NON_THREAD_SAFE 0
+#endif
+
namespace base {
+namespace {
+
// Simple class to exersice the basics of NonThreadSafe.
// Both the destructor and DoStuff should verify that they were
// called on the same thread as the constructor.
@@ -70,6 +80,8 @@ class DeleteNonThreadSafeClassOnThread : public SimpleThread {
DISALLOW_COPY_AND_ASSIGN(DeleteNonThreadSafeClassOnThread);
};
+} // namespace
+
TEST(NonThreadSafeTest, CallsAllowedOnSameThread) {
scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
new NonThreadSafeClass);
@@ -95,7 +107,7 @@ TEST(NonThreadSafeTest, DetachThenDestructOnDifferentThread) {
delete_on_thread.Join();
}
-#if GTEST_HAS_DEATH_TEST || NDEBUG
+#if GTEST_HAS_DEATH_TEST || !ENABLE_NON_THREAD_SAFE
void NonThreadSafeClass::MethodOnDifferentThreadImpl() {
scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
@@ -109,9 +121,9 @@ void NonThreadSafeClass::MethodOnDifferentThreadImpl() {
call_on_thread.Join();
}
-#ifndef NDEBUG
+#if ENABLE_NON_THREAD_SAFE
TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThreadInDebug) {
- ASSERT_DEBUG_DEATH({
+ ASSERT_DEATH({
NonThreadSafeClass::MethodOnDifferentThreadImpl();
}, "");
}
@@ -119,7 +131,7 @@ TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThreadInDebug) {
TEST(NonThreadSafeTest, MethodAllowedOnDifferentThreadInRelease) {
NonThreadSafeClass::MethodOnDifferentThreadImpl();
}
-#endif // NDEBUG
+#endif // ENABLE_NON_THREAD_SAFE
void NonThreadSafeClass::DestructorOnDifferentThreadImpl() {
scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
@@ -134,9 +146,9 @@ void NonThreadSafeClass::DestructorOnDifferentThreadImpl() {
delete_on_thread.Join();
}
-#ifndef NDEBUG
+#if ENABLE_NON_THREAD_SAFE
TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThreadInDebug) {
- ASSERT_DEBUG_DEATH({
+ ASSERT_DEATH({
NonThreadSafeClass::DestructorOnDifferentThreadImpl();
}, "");
}
@@ -144,8 +156,11 @@ TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThreadInDebug) {
TEST(NonThreadSafeTest, DestructorAllowedOnDifferentThreadInRelease) {
NonThreadSafeClass::DestructorOnDifferentThreadImpl();
}
-#endif // NDEBUG
+#endif // ENABLE_NON_THREAD_SAFE
+
+#endif // GTEST_HAS_DEATH_TEST || !ENABLE_NON_THREAD_SAFE
-#endif // GTEST_HAS_DEATH_TEST || NDEBUG
+// Just in case we ever get lumped together with other compilation units.
+#undef ENABLE_NON_THREAD_SAFE
} // namespace base