blob: 971cc65d384d6489d20d3705eceed72a513653f6 [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"
15
16namespace rtc {
17
18SequencedTaskCheckerImpl::SequencedTaskCheckerImpl()
19 : attached_(true), valid_queue_(TaskQueue::Current()) {}
20
21SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {}
22
23bool SequencedTaskCheckerImpl::CalledSequentially() const {
24 TaskQueue* current_queue = TaskQueue::Current();
25 CritScope scoped_lock(&lock_);
26 if (!attached_) { // true if previously detached.
27 valid_queue_ = current_queue;
28 attached_ = true;
29 }
30 if (!valid_queue_)
31 return thread_checker_.CalledOnValidThread();
32 return valid_queue_ == current_queue;
33}
34
35void SequencedTaskCheckerImpl::Detach() {
36 CritScope scoped_lock(&lock_);
37 attached_ = false;
38 valid_queue_ = nullptr;
39 thread_checker_.DetachFromThread();
40}
41
42namespace internal {
43
44SequencedTaskCheckerScope::SequencedTaskCheckerScope(
45 const SequencedTaskChecker* checker) {
46 RTC_DCHECK(checker->CalledSequentially());
47}
48
49SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {}
50
51} // namespace internal
52} // namespace rtc