Danil Chapovalov | b4c6d1e | 2019-01-21 13:52:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | #include "rtc_base/task_queue.h" |
| 11 | |
| 12 | #include "api/task_queue/global_task_queue_factory.h" |
| 13 | #include "api/task_queue/task_queue_base.h" |
| 14 | |
| 15 | namespace rtc { |
| 16 | |
| 17 | TaskQueue::TaskQueue(const char* queue_name, Priority priority) |
Danil Chapovalov | b4c6d1e | 2019-01-21 13:52:59 +0100 | [diff] [blame] | 18 | : impl_(webrtc::GlobalTaskQueueFactory() |
| 19 | .CreateTaskQueue(queue_name, priority) |
| 20 | .release()) { |
| 21 | impl_->task_queue_ = this; |
| 22 | } |
| 23 | |
| 24 | TaskQueue::~TaskQueue() { |
Danil Chapovalov | b4c6d1e | 2019-01-21 13:52:59 +0100 | [diff] [blame] | 25 | impl_->Delete(); |
Danil Chapovalov | b4c6d1e | 2019-01-21 13:52:59 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // static |
| 29 | TaskQueue* TaskQueue::Current() { |
| 30 | webrtc::TaskQueueBase* impl = webrtc::TaskQueueBase::Current(); |
| 31 | if (impl == nullptr) { |
| 32 | return nullptr; |
| 33 | } |
| 34 | return impl->task_queue_; |
| 35 | } |
| 36 | |
| 37 | bool TaskQueue::IsCurrent() const { |
| 38 | return Current() == this; |
| 39 | } |
| 40 | |
| 41 | void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) { |
| 42 | return impl_->PostTask(std::move(task)); |
| 43 | } |
| 44 | |
| 45 | void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, |
| 46 | uint32_t milliseconds) { |
| 47 | return impl_->PostDelayedTask(std::move(task), milliseconds); |
| 48 | } |
| 49 | |
| 50 | } // namespace rtc |