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

Side by Side Diff: webrtc/base/thread_scope.h

Issue 1967193002: ThreadScope concept to check variable accessed on correct thread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: generalized ThreadScope Created 4 years, 7 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/thread_checker.h ('k') | webrtc/p2p/stunprober/stunprober.cc » ('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 #ifndef WEBRTC_BASE_THREAD_SCOPE_H_
12 #define WEBRTC_BASE_THREAD_SCOPE_H_
13
14 #include "webrtc/base/checks.h"
15 // #include webrtc/base/task_queue.h"
16 #include "webrtc/base/thread.h"
17 #include "webrtc/base/thread_annotations.h"
18 #include "webrtc/base/thread_checker.h"
19
20 namespace rtc {
21 // ThreadScope mimic CritScope.
22 class SCOPED_LOCKABLE ThreadScope {
23 public:
24 template<typename ThreadLikeObject>
25 explicit ThreadScope(const ThreadLikeObject* thread)
26 EXCLUSIVE_LOCK_FUNCTION(thread) {}
27
28 static bool IsCurrent(const Thread* thread) {
29 return thread->IsCurrent();
30 }
31 static bool IsCurrent(const ThreadChecker* checker) {
32 return checker->CalledOnValidThread();
33 }
34 /*
35 static bool IsCurrent(const TaskQueue* queue) {
36 return queue->IsCurrent();
37 } */
38
39 ~ThreadScope() UNLOCK_FUNCTION() {}
40 private:
41 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadScope);
42 };
43
44 } // namespace rtc
45
46 // Macro so that DCHECK report correct __FILE__ and __LINE__
47 #define RTC_DCHECK_RUN_ON(thread_like_object) \
48 rtc::ThreadScope check(thread_like_object); \
49 RTC_DCHECK(rtc::ThreadScope::IsCurrent(thread_like_object))
50
51 // Forward macros to avoid word 'lock' when annotating threads
52 #define RTC_MUST_RUN_ON(thread_like_object) \
53 EXCLUSIVE_LOCKS_REQUIRED(thread_like_object)
54 #define RTC_MUST_BE_ACCESSED_FROM(thread_like_object) \
55 GUARDED_BY(thread_like_object)
56
57 #endif // WEBRTC_BASE_THREAD_SCOPE_H_
OLDNEW
« no previous file with comments | « webrtc/base/thread_checker.h ('k') | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698