blob: 06358502a344c660d3d7e0dfeb1cbc881821a563 [file] [log] [blame]
Danil Chapovalovb4c6d1e2019-01-21 13:52:59 +01001/*
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
15namespace rtc {
16
17TaskQueue::TaskQueue(const char* queue_name, Priority priority)
Danil Chapovalovb4c6d1e2019-01-21 13:52:59 +010018 : impl_(webrtc::GlobalTaskQueueFactory()
19 .CreateTaskQueue(queue_name, priority)
20 .release()) {
21 impl_->task_queue_ = this;
22}
23
24TaskQueue::~TaskQueue() {
Danil Chapovalovb4c6d1e2019-01-21 13:52:59 +010025 impl_->Delete();
Danil Chapovalovb4c6d1e2019-01-21 13:52:59 +010026}
27
28// static
29TaskQueue* TaskQueue::Current() {
30 webrtc::TaskQueueBase* impl = webrtc::TaskQueueBase::Current();
31 if (impl == nullptr) {
32 return nullptr;
33 }
34 return impl->task_queue_;
35}
36
37bool TaskQueue::IsCurrent() const {
38 return Current() == this;
39}
40
41void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) {
42 return impl_->PostTask(std::move(task));
43}
44
45void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
46 uint32_t milliseconds) {
47 return impl_->PostDelayedTask(std::move(task), milliseconds);
48}
49
50} // namespace rtc