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.cc. 12 13#include "webrtc/base/thread_checker_impl.h" 14 15#include "webrtc/base/thread.h" 16 17namespace rtc { 18 19ThreadCheckerImpl::ThreadCheckerImpl() 20 : valid_thread_() { 21 EnsureThreadIdAssigned(); 22} 23 24ThreadCheckerImpl::~ThreadCheckerImpl() { 25} 26 27bool ThreadCheckerImpl::CalledOnValidThread() const { 28 CritScope scoped_lock(&lock_); 29 EnsureThreadIdAssigned(); 30 return valid_thread_->IsCurrent(); 31} 32 33void ThreadCheckerImpl::DetachFromThread() { 34 CritScope scoped_lock(&lock_); 35 valid_thread_ = NULL; 36} 37 38void ThreadCheckerImpl::EnsureThreadIdAssigned() const { 39 if (!valid_thread_) { 40 valid_thread_ = Thread::Current(); 41 } 42} 43 44} // namespace rtc 45