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

Side by Side 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: RUNS_SYNCHRONIZED Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/race_checker.h ('k') | webrtc/common_video/include/incoming_video_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/base/race_checker.h"
12
13 namespace rtc {
14 RaceChecker::RaceChecker() {}
danilchap 2016/06/28 13:48:12 empty line after the constructor would look nicer.
pbos-webrtc 2016/06/28 15:05:43 Done.
15 bool RaceChecker::Acquire() const {
16 const PlatformThreadRef current_thread = CurrentThreadRef();
17 // Set new accessing thread if this is a new use.
18 if (access_count_++ == 0)
19 accessing_thread_ = current_thread;
20 // If this is being used concurrently this check will fail for the second
21 // thread entering since it won't set the thread. Recursive use of checked
22 // methods are OK since the accessing thread remains the same.
23 const PlatformThreadRef accessing_thread = accessing_thread_;
24 return IsThreadRefEqual(accessing_thread, current_thread);
25 }
26
27 void RaceChecker::Release() const {
28 --access_count_;
29 }
30
31 namespace internal {
32 RaceCheckerScope::RaceCheckerScope(const RaceChecker* race_checker)
33 : race_checker_(race_checker), race_check_ok_(race_checker->Acquire()) {}
34
35 bool RaceCheckerScope::RaceDetected() const {
36 return !race_check_ok_;
37 }
38
39 RaceCheckerScope::~RaceCheckerScope() {
40 race_checker_->Release();
41 }
42
43 } // namespace internal
44 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/race_checker.h ('k') | webrtc/common_video/include/incoming_video_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698