blob: 615f44c2b52e8562c182159748b418c4b40729ce [file] [log] [blame]
perkj9c16fe82016-07-12 15:04:07 -07001/*
2 * Copyright (c) 2016 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#include "webrtc/base/sequenced_task_checker_impl.h"
12
13#include "webrtc/base/platform_thread.h"
14#include "webrtc/base/sequenced_task_checker.h"
perkj32012f82016-07-14 23:32:08 -070015#include "webrtc/base/task_queue.h"
perkj9c16fe82016-07-12 15:04:07 -070016
17namespace rtc {
18
19SequencedTaskCheckerImpl::SequencedTaskCheckerImpl()
20 : attached_(true), valid_queue_(TaskQueue::Current()) {}
21
22SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {}
23
24bool SequencedTaskCheckerImpl::CalledSequentially() const {
25 TaskQueue* current_queue = TaskQueue::Current();
26 CritScope scoped_lock(&lock_);
27 if (!attached_) { // true if previously detached.
28 valid_queue_ = current_queue;
29 attached_ = true;
30 }
31 if (!valid_queue_)
32 return thread_checker_.CalledOnValidThread();
33 return valid_queue_ == current_queue;
34}
35
36void SequencedTaskCheckerImpl::Detach() {
37 CritScope scoped_lock(&lock_);
38 attached_ = false;
39 valid_queue_ = nullptr;
40 thread_checker_.DetachFromThread();
41}
42
43namespace internal {
44
45SequencedTaskCheckerScope::SequencedTaskCheckerScope(
46 const SequencedTaskChecker* checker) {
47 RTC_DCHECK(checker->CalledSequentially());
48}
49
50SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {}
51
52} // namespace internal
53} // namespace rtc