Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: webrtc/base/race_checker.cc

Issue 2097403002: Add a race-checking mechanism. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: bah Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/race_checker.cc
diff --git a/webrtc/base/race_checker.cc b/webrtc/base/race_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a492726de21c19f8ff34486ccb29c687385ace69
--- /dev/null
+++ b/webrtc/base/race_checker.cc
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/base/race_checker.h"
+
+namespace rtc {
+RaceChecker::RaceChecker() {}
+bool RaceChecker::Acquire() const {
+ const PlatformThreadRef current_thread = CurrentThreadRef();
+ // Set new accessing thread if this is a new use.
+ if (access_count_++ == 0)
+ accessing_thread_ = current_thread;
+ // If this is being used concurrently this check will fail for the second
+ // thread entering since it won't set the thread. Recursive use of checked
+ // methods are OK since the accessing thread remains the same.
+ return IsThreadRefEqual(
+ const_cast<const PlatformThreadRef&>(accessing_thread_), current_thread);
danilchap 2016/06/27 17:58:57 may be const PlatformThreadRef accessing_thread =
pbos-webrtc 2016/06/27 18:06:39 Done.
+}
+
+void RaceChecker::Release() const {
+ --access_count_;
+}
+
+namespace internal {
+RaceCheckerScope::RaceCheckerScope(const RaceChecker* race_checker)
+ : race_checker_(race_checker), race_check_ok_(race_checker->Acquire()) {}
+
+bool RaceCheckerScope::RaceDetected() const {
+ return !race_check_ok_;
+}
+
+RaceCheckerScope::~RaceCheckerScope() {
+ race_checker_->Release();
+}
+
+} // namespace internal
+} // namespace rtc

Powered by Google App Engine
This is Rietveld 408576698