| 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 #if defined(WEBRTC_MAC) | |
| 14 #include <dispatch/dispatch.h> | |
| 15 #endif | |
| 16 | |
| 17 #include "webrtc/base/platform_thread.h" | |
| 18 #include "webrtc/base/sequenced_task_checker.h" | |
| 19 #include "webrtc/base/task_queue.h" | |
| 20 | |
| 21 namespace rtc { | |
| 22 | |
| 23 SequencedTaskCheckerImpl::SequencedTaskCheckerImpl() | |
| 24 : attached_(true), valid_queue_(TaskQueue::Current()) {} | |
| 25 | |
| 26 SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {} | |
| 27 | |
| 28 bool SequencedTaskCheckerImpl::CalledSequentially() const { | |
| 29 QueueId current_queue = TaskQueue::Current(); | |
| 30 #if defined(WEBRTC_MAC) | |
| 31 // If we're not running on a TaskQueue, use the system dispatch queue | |
| 32 // label as an identifier. | |
| 33 if (current_queue == nullptr) | |
| 34 current_queue = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); | |
| 35 #endif | |
| 36 CritScope scoped_lock(&lock_); | |
| 37 if (!attached_) { // true if previously detached. | |
| 38 valid_queue_ = current_queue; | |
| 39 attached_ = true; | |
| 40 } | |
| 41 if (!valid_queue_) | |
| 42 return thread_checker_.CalledOnValidThread(); | |
| 43 return valid_queue_ == current_queue; | |
| 44 } | |
| 45 | |
| 46 void SequencedTaskCheckerImpl::Detach() { | |
| 47 CritScope scoped_lock(&lock_); | |
| 48 attached_ = false; | |
| 49 valid_queue_ = nullptr; | |
| 50 thread_checker_.DetachFromThread(); | |
| 51 } | |
| 52 | |
| 53 namespace internal { | |
| 54 | |
| 55 SequencedTaskCheckerScope::SequencedTaskCheckerScope( | |
| 56 const SequencedTaskChecker* checker) { | |
| 57 RTC_DCHECK(checker->CalledSequentially()); | |
| 58 } | |
| 59 | |
| 60 SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {} | |
| 61 | |
| 62 } // namespace internal | |
| 63 } // namespace rtc | |
| OLD | NEW |