blob: 79be6064453700b24d86f49b4c7d14a242c16ba6 [file] [log] [blame]
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:441/*
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.cc.
12
Henrik Kjellander7b8e1822017-06-30 13:14:4513#include "webrtc/base/thread_checker_impl.h"
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:4414
Henrik Kjellander7b8e1822017-06-30 13:14:4515#include "webrtc/base/platform_thread.h"
pbos9410e012015-11-23 22:47:5616
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:4417namespace rtc {
tommi@webrtc.org1514b942015-02-03 16:29:5718
tommi@webrtc.org8454c032015-02-07 19:17:4719ThreadCheckerImpl::ThreadCheckerImpl() : valid_thread_(CurrentThreadRef()) {
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:4420}
21
22ThreadCheckerImpl::~ThreadCheckerImpl() {
23}
24
25bool ThreadCheckerImpl::CalledOnValidThread() const {
tommi@webrtc.org8454c032015-02-07 19:17:4726 const PlatformThreadRef current_thread = CurrentThreadRef();
tommi@webrtc.org699e3312015-02-06 15:39:0527 CritScope scoped_lock(&lock_);
tommi@webrtc.orga69cf7d2015-01-26 15:27:2928 if (!valid_thread_) // Set if previously detached.
29 valid_thread_ = current_thread;
tommi@webrtc.org8454c032015-02-07 19:17:4730 return IsThreadRefEqual(valid_thread_, current_thread);
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:4431}
32
33void ThreadCheckerImpl::DetachFromThread() {
34 CritScope scoped_lock(&lock_);
tommi@webrtc.orga69cf7d2015-01-26 15:27:2935 valid_thread_ = 0;
henrik.lundin@webrtc.orgd3a28862014-06-16 11:34:4436}
37
38} // namespace rtc