blob: 7b39ada0ca200929b8bb50790f9bf5e1ee86be1f [file] [log] [blame]
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +00001/*
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
13#ifndef WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
14#define WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
15
16#include "webrtc/base/criticalsection.h"
Tommibebc6902015-05-18 09:51:42 +020017#include "webrtc/base/platform_thread.h"
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +000018
19namespace rtc {
20
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +000021// Real implementation of ThreadChecker, for use in debug mode, or
henrikg91d6ede2015-09-17 00:24:34 -070022// for temporary use in release mode (e.g. to RTC_CHECK on a threading issue
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +000023// 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.
27class 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:
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +000040 mutable CriticalSection lock_;
41 // This is mutable so that CalledOnValidThread can set it.
42 // It's guarded by |lock_|.
tommi@webrtc.org2eb16602015-02-07 19:17:47 +000043 mutable PlatformThreadRef valid_thread_;
henrik.lundin@webrtc.org1e3c5c22014-06-16 11:34:44 +000044};
45
46} // namespace rtc
47
48#endif // WEBRTC_BASE_THREAD_CHECKER_IMPL_H_