Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 11 | #include "rtc_base/task_queue_stdlib.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 15 | #include <algorithm> |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 16 | #include <map> |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 17 | #include <memory> |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 18 | #include <queue> |
| 19 | #include <utility> |
| 20 | |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 21 | #include "absl/functional/any_invocable.h" |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 22 | #include "absl/strings/string_view.h" |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 23 | #include "api/task_queue/task_queue_base.h" |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 24 | #include "api/units/time_delta.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 25 | #include "rtc_base/checks.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 26 | #include "rtc_base/event.h" |
| 27 | #include "rtc_base/logging.h" |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 28 | #include "rtc_base/numerics/divide_round.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 29 | #include "rtc_base/platform_thread.h" |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 30 | #include "rtc_base/synchronization/mutex.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 31 | #include "rtc_base/thread_annotations.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 32 | #include "rtc_base/time_utils.h" |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 33 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 34 | namespace webrtc { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 35 | namespace { |
| 36 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 37 | rtc::ThreadPriority TaskQueuePriorityToThreadPriority( |
| 38 | TaskQueueFactory::Priority priority) { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 39 | switch (priority) { |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 40 | case TaskQueueFactory::Priority::HIGH: |
Markus Handell | ad5037b | 2021-05-07 13:02:36 | [diff] [blame] | 41 | return rtc::ThreadPriority::kRealtime; |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 42 | case TaskQueueFactory::Priority::LOW: |
Markus Handell | ad5037b | 2021-05-07 13:02:36 | [diff] [blame] | 43 | return rtc::ThreadPriority::kLow; |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 44 | case TaskQueueFactory::Priority::NORMAL: |
Markus Handell | ad5037b | 2021-05-07 13:02:36 | [diff] [blame] | 45 | return rtc::ThreadPriority::kNormal; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 46 | } |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 47 | } |
| 48 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 49 | class TaskQueueStdlib final : public TaskQueueBase { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 50 | public: |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 51 | TaskQueueStdlib(absl::string_view queue_name, rtc::ThreadPriority priority); |
| 52 | ~TaskQueueStdlib() override = default; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 53 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 54 | void Delete() override; |
Markus Handell | 2a256c8 | 2023-02-27 11:41:39 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | void PostTaskImpl(absl::AnyInvocable<void() &&> task, |
| 58 | const PostTaskTraits& traits, |
| 59 | const Location& location) override; |
| 60 | void PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task, |
| 61 | TimeDelta delay, |
| 62 | const PostDelayedTaskTraits& traits, |
| 63 | const Location& location) override; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 64 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 65 | private: |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 66 | using OrderId = uint64_t; |
| 67 | |
| 68 | struct DelayedEntryTimeout { |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 | [diff] [blame] | 69 | // TODO(bugs.webrtc.org/13756): Migrate to Timestamp. |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 70 | int64_t next_fire_at_us{}; |
| 71 | OrderId order{}; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 72 | |
| 73 | bool operator<(const DelayedEntryTimeout& o) const { |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 74 | return std::tie(next_fire_at_us, order) < |
| 75 | std::tie(o.next_fire_at_us, o.order); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 76 | } |
| 77 | }; |
| 78 | |
| 79 | struct NextTask { |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 80 | bool final_task = false; |
| 81 | absl::AnyInvocable<void() &&> run_task; |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 | [diff] [blame] | 82 | TimeDelta sleep_time = rtc::Event::kForever; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 83 | }; |
| 84 | |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 85 | static rtc::PlatformThread InitializeThread(TaskQueueStdlib* me, |
| 86 | absl::string_view queue_name, |
| 87 | rtc::ThreadPriority priority); |
| 88 | |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 89 | NextTask GetNextTask(); |
| 90 | |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 91 | void ProcessTasks(); |
| 92 | |
| 93 | void NotifyWake(); |
| 94 | |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 95 | // Signaled whenever a new task is pending. |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 96 | rtc::Event flag_notify_; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 97 | |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 98 | Mutex pending_lock_; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 99 | |
| 100 | // Indicates if the worker thread needs to shutdown now. |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 101 | bool thread_should_quit_ RTC_GUARDED_BY(pending_lock_) = false; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 102 | |
| 103 | // Holds the next order to use for the next task to be |
| 104 | // put into one of the pending queues. |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 105 | OrderId thread_posting_order_ RTC_GUARDED_BY(pending_lock_) = 0; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 106 | |
| 107 | // The list of all pending tasks that need to be processed in the |
| 108 | // FIFO queue ordering on the worker thread. |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 109 | std::queue<std::pair<OrderId, absl::AnyInvocable<void() &&>>> pending_queue_ |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 110 | RTC_GUARDED_BY(pending_lock_); |
| 111 | |
| 112 | // The list of all pending tasks that need to be processed at a future |
| 113 | // time based upon a delay. On the off change the delayed task should |
| 114 | // happen at exactly the same time interval as another task then the |
| 115 | // task is processed based on FIFO ordering. std::priority_queue was |
| 116 | // considered but rejected due to its inability to extract the |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 117 | // move-only value out of the queue without the presence of a hack. |
| 118 | std::map<DelayedEntryTimeout, absl::AnyInvocable<void() &&>> delayed_queue_ |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 119 | RTC_GUARDED_BY(pending_lock_); |
Markus Handell | 49cb459 | 2021-06-22 08:02:26 | [diff] [blame] | 120 | |
| 121 | // Contains the active worker thread assigned to processing |
| 122 | // tasks (including delayed tasks). |
| 123 | // Placing this last ensures the thread doesn't touch uninitialized attributes |
| 124 | // throughout it's lifetime. |
| 125 | rtc::PlatformThread thread_; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 126 | }; |
| 127 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 128 | TaskQueueStdlib::TaskQueueStdlib(absl::string_view queue_name, |
| 129 | rtc::ThreadPriority priority) |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 130 | : flag_notify_(/*manual_reset=*/false, /*initially_signaled=*/false), |
| 131 | thread_(InitializeThread(this, queue_name, priority)) {} |
| 132 | |
| 133 | // static |
| 134 | rtc::PlatformThread TaskQueueStdlib::InitializeThread( |
| 135 | TaskQueueStdlib* me, |
| 136 | absl::string_view queue_name, |
| 137 | rtc::ThreadPriority priority) { |
| 138 | rtc::Event started; |
| 139 | auto thread = rtc::PlatformThread::SpawnJoinable( |
| 140 | [&started, me] { |
| 141 | CurrentTaskQueueSetter set_current(me); |
| 142 | started.Set(); |
| 143 | me->ProcessTasks(); |
| 144 | }, |
| 145 | queue_name, rtc::ThreadAttributes().SetPriority(priority)); |
| 146 | started.Wait(rtc::Event::kForever); |
| 147 | return thread; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 148 | } |
| 149 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 150 | void TaskQueueStdlib::Delete() { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 151 | RTC_DCHECK(!IsCurrent()); |
| 152 | |
| 153 | { |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 154 | MutexLock lock(&pending_lock_); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 155 | thread_should_quit_ = true; |
| 156 | } |
| 157 | |
| 158 | NotifyWake(); |
| 159 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 160 | delete this; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 161 | } |
| 162 | |
Markus Handell | 2a256c8 | 2023-02-27 11:41:39 | [diff] [blame] | 163 | void TaskQueueStdlib::PostTaskImpl(absl::AnyInvocable<void() &&> task, |
| 164 | const PostTaskTraits& traits, |
| 165 | const Location& location) { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 166 | { |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 167 | MutexLock lock(&pending_lock_); |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 168 | pending_queue_.push( |
| 169 | std::make_pair(++thread_posting_order_, std::move(task))); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | NotifyWake(); |
| 173 | } |
| 174 | |
Markus Handell | 2a256c8 | 2023-02-27 11:41:39 | [diff] [blame] | 175 | void TaskQueueStdlib::PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task, |
| 176 | TimeDelta delay, |
| 177 | const PostDelayedTaskTraits& traits, |
| 178 | const Location& location) { |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 179 | DelayedEntryTimeout delayed_entry; |
| 180 | delayed_entry.next_fire_at_us = rtc::TimeMicros() + delay.us(); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 181 | |
| 182 | { |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 183 | MutexLock lock(&pending_lock_); |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 184 | delayed_entry.order = ++thread_posting_order_; |
| 185 | delayed_queue_[delayed_entry] = std::move(task); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | NotifyWake(); |
| 189 | } |
| 190 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 191 | TaskQueueStdlib::NextTask TaskQueueStdlib::GetNextTask() { |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 192 | NextTask result; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 193 | |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 194 | const int64_t tick_us = rtc::TimeMicros(); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 195 | |
Markus Handell | 18523c3 | 2020-07-08 15:55:58 | [diff] [blame] | 196 | MutexLock lock(&pending_lock_); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 197 | |
| 198 | if (thread_should_quit_) { |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 199 | result.final_task = true; |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 200 | return result; |
| 201 | } |
| 202 | |
| 203 | if (delayed_queue_.size() > 0) { |
| 204 | auto delayed_entry = delayed_queue_.begin(); |
| 205 | const auto& delay_info = delayed_entry->first; |
| 206 | auto& delay_run = delayed_entry->second; |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 207 | if (tick_us >= delay_info.next_fire_at_us) { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 208 | if (pending_queue_.size() > 0) { |
| 209 | auto& entry = pending_queue_.front(); |
| 210 | auto& entry_order = entry.first; |
| 211 | auto& entry_run = entry.second; |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 212 | if (entry_order < delay_info.order) { |
| 213 | result.run_task = std::move(entry_run); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 214 | pending_queue_.pop(); |
| 215 | return result; |
| 216 | } |
| 217 | } |
| 218 | |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 219 | result.run_task = std::move(delay_run); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 220 | delayed_queue_.erase(delayed_entry); |
| 221 | return result; |
| 222 | } |
| 223 | |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 | [diff] [blame] | 224 | result.sleep_time = TimeDelta::Millis( |
| 225 | DivideRoundUp(delay_info.next_fire_at_us - tick_us, 1'000)); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if (pending_queue_.size() > 0) { |
| 229 | auto& entry = pending_queue_.front(); |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 230 | result.run_task = std::move(entry.second); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 231 | pending_queue_.pop(); |
| 232 | } |
| 233 | |
| 234 | return result; |
| 235 | } |
| 236 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 237 | void TaskQueueStdlib::ProcessTasks() { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 238 | while (true) { |
| 239 | auto task = GetNextTask(); |
| 240 | |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 241 | if (task.final_task) |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 242 | break; |
| 243 | |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 244 | if (task.run_task) { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 245 | // process entry immediately then try again |
Danil Chapovalov | ba57001 | 2022-07-19 16:36:31 | [diff] [blame] | 246 | std::move(task.run_task)(); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 247 | |
Tommi | 76d9c18 | 2022-04-22 13:48:37 | [diff] [blame] | 248 | // Attempt to run more tasks before going to sleep. |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 249 | continue; |
| 250 | } |
| 251 | |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 | [diff] [blame] | 252 | flag_notify_.Wait(task.sleep_time); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 253 | } |
Markus Handell | 82da932 | 2022-12-16 14:50:24 | [diff] [blame] | 254 | |
| 255 | // Ensure remaining deleted tasks are destroyed with Current() set up to this |
| 256 | // task queue. |
| 257 | std::queue<std::pair<OrderId, absl::AnyInvocable<void() &&>>> pending_queue; |
| 258 | { |
| 259 | MutexLock lock(&pending_lock_); |
| 260 | pending_queue_.swap(pending_queue); |
| 261 | } |
| 262 | pending_queue = {}; |
| 263 | #if RTC_DCHECK_IS_ON |
| 264 | MutexLock lock(&pending_lock_); |
| 265 | RTC_DCHECK(pending_queue_.empty()); |
| 266 | #endif |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 267 | } |
| 268 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 269 | void TaskQueueStdlib::NotifyWake() { |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 270 | // The queue holds pending tasks to complete. Either tasks are to be |
| 271 | // executed immediately or tasks are to be run at some future delayed time. |
| 272 | // For immediate tasks the task queue's thread is busy running the task and |
| 273 | // the thread will not be waiting on the flag_notify_ event. If no immediate |
| 274 | // tasks are available but a delayed task is pending then the thread will be |
| 275 | // waiting on flag_notify_ with a delayed time-out of the nearest timed task |
| 276 | // to run. If no immediate or pending tasks are available, the thread will |
| 277 | // wait on flag_notify_ until signaled that a task has been added (or the |
| 278 | // thread to be told to shutdown). |
| 279 | |
| 280 | // In all cases, when a new immediate task, delayed task, or request to |
| 281 | // shutdown the thread is added the flag_notify_ is signaled after. If the |
| 282 | // thread was waiting then the thread will wake up immediately and re-assess |
| 283 | // what task needs to be run next (i.e. run a task now, wait for the nearest |
| 284 | // timed delayed task, or shutdown the thread). If the thread was not waiting |
| 285 | // then the thread will remained signaled to wake up the next time any |
| 286 | // attempt to wait on the flag_notify_ event occurs. |
| 287 | |
| 288 | // Any immediate or delayed pending task (or request to shutdown the thread) |
| 289 | // must always be added to the queue prior to signaling flag_notify_ to wake |
| 290 | // up the possibly sleeping thread. This prevents a race condition where the |
| 291 | // thread is notified to wake up but the task queue's thread finds nothing to |
| 292 | // do so it waits once again to be signaled where such a signal may never |
| 293 | // happen. |
| 294 | flag_notify_.Set(); |
| 295 | } |
| 296 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 297 | class TaskQueueStdlibFactory final : public TaskQueueFactory { |
| 298 | public: |
| 299 | std::unique_ptr<TaskQueueBase, TaskQueueDeleter> CreateTaskQueue( |
| 300 | absl::string_view name, |
| 301 | Priority priority) const override { |
| 302 | return std::unique_ptr<TaskQueueBase, TaskQueueDeleter>( |
| 303 | new TaskQueueStdlib(name, TaskQueuePriorityToThreadPriority(priority))); |
| 304 | } |
| 305 | }; |
| 306 | |
| 307 | } // namespace |
| 308 | |
| 309 | std::unique_ptr<TaskQueueFactory> CreateTaskQueueStdlibFactory() { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 310 | return std::make_unique<TaskQueueStdlibFactory>(); |
Robin Raymond | 22027b9 | 2018-11-23 14:07:50 | [diff] [blame] | 311 | } |
| 312 | |
Danil Chapovalov | fa52efa | 2019-02-21 10:13:58 | [diff] [blame] | 313 | } // namespace webrtc |