henrik.lundin@webrtc.org | 1e3c5c2 | 2014-06-16 11:34:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | // Borrowed from Chromium's src/base/threading/thread_checker_impl.h. |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #ifndef RTC_BASE_THREAD_CHECKER_IMPL_H_ |
| 14 | #define RTC_BASE_THREAD_CHECKER_IMPL_H_ |
henrik.lundin@webrtc.org | 1e3c5c2 | 2014-06-16 11:34:44 +0000 | [diff] [blame] | 15 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 16 | #include "rtc_base/critical_section.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/platform_thread_types.h" |
henrik.lundin@webrtc.org | 1e3c5c2 | 2014-06-16 11:34:44 +0000 | [diff] [blame] | 18 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 19 | namespace rtc { |
| 20 | |
| 21 | // Real implementation of ThreadChecker, for use in debug mode, or |
| 22 | // for temporary use in release mode (e.g. to RTC_CHECK on a threading issue |
| 23 | // seen only in the wild). |
| 24 | // |
| 25 | // Note: You should almost always use the ThreadChecker class to get the |
| 26 | // right version for your build configuration. |
| 27 | class ThreadCheckerImpl { |
| 28 | public: |
| 29 | ThreadCheckerImpl(); |
| 30 | ~ThreadCheckerImpl(); |
| 31 | |
| 32 | bool CalledOnValidThread() const; |
| 33 | |
| 34 | // Changes the thread that is checked for in CalledOnValidThread. This may |
| 35 | // be useful when an object may be created on one thread and then used |
| 36 | // exclusively on another thread. |
| 37 | void DetachFromThread(); |
| 38 | |
| 39 | private: |
| 40 | CriticalSection lock_; |
| 41 | // This is mutable so that CalledOnValidThread can set it. |
| 42 | // It's guarded by |lock_|. |
| 43 | mutable PlatformThreadRef valid_thread_; |
| 44 | }; |
| 45 | |
| 46 | } // namespace rtc |
henrik.lundin@webrtc.org | 1e3c5c2 | 2014-06-16 11:34:44 +0000 | [diff] [blame] | 47 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 48 | #endif // RTC_BASE_THREAD_CHECKER_IMPL_H_ |