OLD | NEW |
(Empty) | |
| 1 /* |
| 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 |
| 15 namespace rtc { |
| 16 |
| 17 SequencedTaskCheckerImpl::SequencedTaskCheckerImpl() |
| 18 : attached_(true), valid_queue_(TaskQueue::Current()) {} |
| 19 |
| 20 SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {} |
| 21 |
| 22 bool SequencedTaskCheckerImpl::CalledSequentially() const { |
| 23 TaskQueue* current_queue = TaskQueue::Current(); |
| 24 CritScope scoped_lock(&lock_); |
| 25 if (!attached_) { // true if previously detached. |
| 26 valid_queue_ = current_queue; |
| 27 attached_ = true; |
| 28 } |
| 29 if (!valid_queue_) |
| 30 return thread_checker_.CalledOnValidThread(); |
| 31 return valid_queue_ == current_queue; |
| 32 } |
| 33 |
| 34 void SequencedTaskCheckerImpl::Detach() { |
| 35 CritScope scoped_lock(&lock_); |
| 36 attached_ = false; |
| 37 valid_queue_ = nullptr; |
| 38 thread_checker_.DetachFromThread(); |
| 39 } |
| 40 |
| 41 } // namespace rtc |
OLD | NEW |