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 #include "webrtc/base/sequenced_task_checker.h" |
| 15 |
| 16 namespace rtc { |
| 17 |
| 18 SequencedTaskCheckerImpl::SequencedTaskCheckerImpl() |
| 19 : attached_(true), valid_queue_(TaskQueue::Current()) {} |
| 20 |
| 21 SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {} |
| 22 |
| 23 bool 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 |
| 35 void SequencedTaskCheckerImpl::Detach() { |
| 36 CritScope scoped_lock(&lock_); |
| 37 attached_ = false; |
| 38 valid_queue_ = nullptr; |
| 39 thread_checker_.DetachFromThread(); |
| 40 } |
| 41 |
| 42 namespace internal { |
| 43 |
| 44 SequencedTaskCheckerScope::SequencedTaskCheckerScope( |
| 45 const SequencedTaskChecker* checker) { |
| 46 RTC_DCHECK(checker->CalledSequentially()); |
| 47 } |
| 48 |
| 49 SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {} |
| 50 |
| 51 } // namespace internal |
| 52 } // namespace rtc |
OLD | NEW |