Reland "Add WebRTC specific dcheck_always_on."
This is a reland of 9f2a20f4342a3e86e1f9fdfe6f3d76fb539d41c2
See https://webrtc-review.googlesource.com/c/src/+/226563/1..2
for the fix. RTC_DCHECK_ALWAYS_ON needs to be in public_configs
in order to be propagated together with header #includes and
avoid ODR violations.
Original change's description:
> Add WebRTC specific dcheck_always_on.
>
> Inspired by V8 CL: crrev.com/c/3038528.
>
> This makes the WebRTC's dcheck control independent of Chromium's and
> prepares switching Chromium's default behavior without affecting
> WebRTC developers or builders.
>
> Preparation for: https://crrev.com/c/2893204
>
> Bug: chromium:1225701, webrtc:12988
> Change-Id: Ia0d21f9fb8e9d7704fd1beca16504c301a263b3b
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226465
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Reviewed-by: Markus Handell <handellm@webrtc.org>
> Reviewed-by: Dirk Pranke <dpranke@google.com>
> Cr-Commit-Position: refs/heads/master@{#34512}
Bug: chromium:1225701, webrtc:12988
Change-Id: I1f78587487ee7b1a4a07b8c91b737a9e797b2323
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226563
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34519}
diff --git a/rtc_base/checks.h b/rtc_base/checks.h
index 21fca7e..e7584fb 100644
--- a/rtc_base/checks.h
+++ b/rtc_base/checks.h
@@ -14,7 +14,7 @@
// If you for some reson need to know if DCHECKs are on, test the value of
// RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be
// defined, to either a true or a false value.)
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+#if !defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON)
#define RTC_DCHECK_IS_ON 1
#else
#define RTC_DCHECK_IS_ON 0
diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc
index 8ca9ce7..b54cded 100644
--- a/rtc_base/thread.cc
+++ b/rtc_base/thread.cc
@@ -1044,7 +1044,7 @@
}
void Thread::AllowInvokesToThread(Thread* thread) {
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if (!defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON))
if (!IsCurrent()) {
PostTask(webrtc::ToQueuedTask(
[thread, this]() { AllowInvokesToThread(thread); }));
@@ -1057,7 +1057,7 @@
}
void Thread::DisallowAllInvokes() {
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if (!defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON))
if (!IsCurrent()) {
PostTask(webrtc::ToQueuedTask([this]() { DisallowAllInvokes(); }));
return;
@@ -1082,7 +1082,7 @@
// Returns true if no policies added or if there is at least one policy
// that permits invocation to |target| thread.
bool Thread::IsInvokeToThreadAllowed(rtc::Thread* target) {
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if (!defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON))
RTC_DCHECK_RUN_ON(this);
if (!invoke_policy_enabled_) {
return true;
diff --git a/rtc_base/thread.h b/rtc_base/thread.h
index 6e68f1a..cb5a0e9 100644
--- a/rtc_base/thread.h
+++ b/rtc_base/thread.h
@@ -400,15 +400,17 @@
// Allows invoke to specified |thread|. Thread never will be dereferenced and
// will be used only for reference-based comparison, so instance can be safely
- // deleted. If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined do nothing.
+ // deleted. If NDEBUG is defined and RTC_DCHECK_ALWAYS_ON is undefined do
+ // nothing.
void AllowInvokesToThread(Thread* thread);
- // If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined do nothing.
+ // If NDEBUG is defined and RTC_DCHECK_ALWAYS_ON is undefined do nothing.
void DisallowAllInvokes();
// Returns true if |target| was allowed by AllowInvokesToThread() or if no
// calls were made to AllowInvokesToThread and DisallowAllInvokes. Otherwise
// returns false.
- // If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined always returns true.
+ // If NDEBUG is defined and RTC_DCHECK_ALWAYS_ON is undefined always returns
+ // true.
bool IsInvokeToThreadAllowed(rtc::Thread* target);
// Posts a task to invoke the functor on |this| thread asynchronously, i.e.
diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc
index 789bdd9..e603930 100644
--- a/rtc_base/thread_unittest.cc
+++ b/rtc_base/thread_unittest.cc
@@ -366,7 +366,7 @@
ThreadManager::Instance()->SetCurrentThread(current_thread);
}
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if (!defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON))
TEST(ThreadTest, InvokeToThreadAllowedReturnsTrueWithoutPolicies) {
// Create and start the thread.
auto thread1 = Thread::CreateWithSocketServer();
@@ -410,7 +410,7 @@
Thread* th_main = Thread::Current();
th_main->ProcessMessages(100);
}
-#endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#endif // (!defined(NDEBUG) || defined(RTC_DCHECK_ALWAYS_ON))
TEST(ThreadTest, InvokesAllowedByDefault) {
// Create and start the thread.