OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/sequenced_task_checker_impl.h" | 11 #include "webrtc/base/sequenced_task_checker_impl.h" |
12 | 12 |
| 13 #if defined(WEBRTC_MAC) |
| 14 #include <dispatch/dispatch.h> |
| 15 #endif |
| 16 |
13 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
14 #include "webrtc/base/sequenced_task_checker.h" | 18 #include "webrtc/base/sequenced_task_checker.h" |
15 #include "webrtc/base/task_queue.h" | 19 #include "webrtc/base/task_queue.h" |
16 | 20 |
17 namespace rtc { | 21 namespace rtc { |
18 | 22 |
19 SequencedTaskCheckerImpl::SequencedTaskCheckerImpl() | 23 SequencedTaskCheckerImpl::SequencedTaskCheckerImpl() |
20 : attached_(true), valid_queue_(TaskQueue::Current()) {} | 24 : attached_(true), valid_queue_(TaskQueue::Current()) {} |
21 | 25 |
22 SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {} | 26 SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {} |
23 | 27 |
24 bool SequencedTaskCheckerImpl::CalledSequentially() const { | 28 bool SequencedTaskCheckerImpl::CalledSequentially() const { |
25 TaskQueue* current_queue = TaskQueue::Current(); | 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 |
26 CritScope scoped_lock(&lock_); | 36 CritScope scoped_lock(&lock_); |
27 if (!attached_) { // true if previously detached. | 37 if (!attached_) { // true if previously detached. |
28 valid_queue_ = current_queue; | 38 valid_queue_ = current_queue; |
29 attached_ = true; | 39 attached_ = true; |
30 } | 40 } |
31 if (!valid_queue_) | 41 if (!valid_queue_) |
32 return thread_checker_.CalledOnValidThread(); | 42 return thread_checker_.CalledOnValidThread(); |
33 return valid_queue_ == current_queue; | 43 return valid_queue_ == current_queue; |
34 } | 44 } |
35 | 45 |
36 void SequencedTaskCheckerImpl::Detach() { | 46 void SequencedTaskCheckerImpl::Detach() { |
37 CritScope scoped_lock(&lock_); | 47 CritScope scoped_lock(&lock_); |
38 attached_ = false; | 48 attached_ = false; |
39 valid_queue_ = nullptr; | 49 valid_queue_ = nullptr; |
40 thread_checker_.DetachFromThread(); | 50 thread_checker_.DetachFromThread(); |
41 } | 51 } |
42 | 52 |
43 namespace internal { | 53 namespace internal { |
44 | 54 |
45 SequencedTaskCheckerScope::SequencedTaskCheckerScope( | 55 SequencedTaskCheckerScope::SequencedTaskCheckerScope( |
46 const SequencedTaskChecker* checker) { | 56 const SequencedTaskChecker* checker) { |
47 RTC_DCHECK(checker->CalledSequentially()); | 57 RTC_DCHECK(checker->CalledSequentially()); |
48 } | 58 } |
49 | 59 |
50 SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {} | 60 SequencedTaskCheckerScope::~SequencedTaskCheckerScope() {} |
51 | 61 |
52 } // namespace internal | 62 } // namespace internal |
53 } // namespace rtc | 63 } // namespace rtc |
OLD | NEW |