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
13#ifndef WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
14#define WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
15
16#include "webrtc/base/criticalsection.h"
17
18namespace rtc {
19
20class Thread;
21
22// Real implementation of ThreadChecker, for use in debug mode, or
23// for temporary use in release mode (e.g. to CHECK on a threading issue
24// seen only in the wild).
25//
26// Note: You should almost always use the ThreadChecker class to get the
27// right version for your build configuration.
28class ThreadCheckerImpl {
29 public:
30  ThreadCheckerImpl();
31  ~ThreadCheckerImpl();
32
33  bool CalledOnValidThread() const;
34
35  // Changes the thread that is checked for in CalledOnValidThread.  This may
36  // be useful when an object may be created on one thread and then used
37  // exclusively on another thread.
38  void DetachFromThread();
39
40 private:
41  void EnsureThreadIdAssigned() const;
42
43  mutable CriticalSection lock_;
44  // This is mutable so that CalledOnValidThread can set it.
45  // It's guarded by |lock_|.
46  mutable const Thread* valid_thread_;
47};
48
49}  // namespace rtc
50
51#endif  // WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
52