blob: 513ccd72cc67a9aa1b28fb8d9e4f315ff7bac8db [file] [log] [blame]
tommic06b1332016-05-14 18:31:401/*
2 * Copyright 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
Danil Chapovalov826f2e72019-02-20 17:13:0911#include "rtc_base/task_queue_win.h"
tommic06b1332016-05-14 18:31:4012
Yves Gerey665174f2018-06-19 13:03:0513// clang-format off
14// clang formating would change include order.
15
Danil Chapovalov02fddf62018-02-12 11:41:1616// Include winsock2.h before including <windows.h> to maintain consistency with
Niels Möllerb06b0a62018-05-25 08:05:3417// win32.h. To include win32.h directly, it must be broken out into its own
18// build target.
Danil Chapovalov02fddf62018-02-12 11:41:1619#include <winsock2.h>
20#include <windows.h>
Yves Gerey665174f2018-06-19 13:03:0521#include <sal.h> // Must come after windows headers.
Danil Chapovalov02fddf62018-02-12 11:41:1622#include <mmsystem.h> // Must come after windows headers.
Yves Gerey665174f2018-06-19 13:03:0523// clang-format on
tommic06b1332016-05-14 18:31:4024#include <string.h>
tommic06b1332016-05-14 18:31:4025
tommif9d91542017-02-17 10:47:1126#include <algorithm>
Danil Chapovalov3c06cfc2022-07-20 11:38:5827#include <functional>
Mirko Bonadei317a1f02019-09-17 15:06:1828#include <memory>
Florent Castelli8037fc62024-08-29 13:00:4029#include <optional>
tommi0b942152017-03-10 17:33:5330#include <queue>
Danil Chapovalov6f09ae22017-10-12 12:39:2531#include <utility>
tommif9d91542017-02-17 10:47:1132
Danil Chapovalov3c06cfc2022-07-20 11:38:5833#include "absl/functional/any_invocable.h"
Danil Chapovalov826f2e72019-02-20 17:13:0934#include "absl/strings/string_view.h"
Danil Chapovalov826f2e72019-02-20 17:13:0935#include "api/task_queue/task_queue_base.h"
Danil Chapovalov3c06cfc2022-07-20 11:38:5836#include "api/units/time_delta.h"
37#include "api/units/timestamp.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3138#include "rtc_base/arraysize.h"
39#include "rtc_base/checks.h"
40#include "rtc_base/event.h"
41#include "rtc_base/logging.h"
Karl Wiberge40468b2017-11-22 09:42:2642#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3143#include "rtc_base/platform_thread.h"
Markus Handell18523c32020-07-08 15:55:5844#include "rtc_base/synchronization/mutex.h"
Markus Handellad5037b2021-05-07 13:02:3645#include "rtc_base/time_utils.h"
tommic06b1332016-05-14 18:31:4046
Danil Chapovalov826f2e72019-02-20 17:13:0947namespace webrtc {
tommic06b1332016-05-14 18:31:4048namespace {
tommic06b1332016-05-14 18:31:4049#define WM_QUEUE_DELAYED_TASK WM_USER + 2
50
tommic06b1332016-05-14 18:31:4051void CALLBACK InitializeQueueThread(ULONG_PTR param) {
52 MSG msg;
tommif9d91542017-02-17 10:47:1153 ::PeekMessage(&msg, nullptr, WM_USER, WM_USER, PM_NOREMOVE);
Danil Chapovalov826f2e72019-02-20 17:13:0954 rtc::Event* data = reinterpret_cast<rtc::Event*>(param);
55 data->Set();
tommic06b1332016-05-14 18:31:4056}
tommic9bb7912017-02-24 18:42:1457
Danil Chapovalov826f2e72019-02-20 17:13:0958rtc::ThreadPriority TaskQueuePriorityToThreadPriority(
59 TaskQueueFactory::Priority priority) {
tommic9bb7912017-02-24 18:42:1460 switch (priority) {
Danil Chapovalov826f2e72019-02-20 17:13:0961 case TaskQueueFactory::Priority::HIGH:
Markus Handellad5037b2021-05-07 13:02:3662 return rtc::ThreadPriority::kRealtime;
Danil Chapovalov826f2e72019-02-20 17:13:0963 case TaskQueueFactory::Priority::LOW:
Markus Handellad5037b2021-05-07 13:02:3664 return rtc::ThreadPriority::kLow;
Danil Chapovalov826f2e72019-02-20 17:13:0965 case TaskQueueFactory::Priority::NORMAL:
Markus Handellad5037b2021-05-07 13:02:3666 return rtc::ThreadPriority::kNormal;
tommic9bb7912017-02-24 18:42:1467 }
tommic9bb7912017-02-24 18:42:1468}
tommi5bdee472017-03-03 13:20:1269
Danil Chapovalov3c06cfc2022-07-20 11:38:5870Timestamp CurrentTime() {
tommi5bdee472017-03-03 13:20:1271 static const UINT kPeriod = 1;
72 bool high_res = (timeBeginPeriod(kPeriod) == TIMERR_NOERROR);
Danil Chapovalov3c06cfc2022-07-20 11:38:5873 Timestamp ret = Timestamp::Micros(rtc::TimeMicros());
tommi5bdee472017-03-03 13:20:1274 if (high_res)
75 timeEndPeriod(kPeriod);
76 return ret;
77}
tommic06b1332016-05-14 18:31:4078
tommi0b942152017-03-10 17:33:5379class DelayedTaskInfo {
tommif9d91542017-02-17 10:47:1180 public:
tommi0b942152017-03-10 17:33:5381 // Default ctor needed to support priority_queue::pop().
82 DelayedTaskInfo() {}
Danil Chapovalov3c06cfc2022-07-20 11:38:5883 DelayedTaskInfo(TimeDelta delay, absl::AnyInvocable<void() &&> task)
84 : due_time_(CurrentTime() + delay), task_(std::move(task)) {}
tommi0b942152017-03-10 17:33:5385 DelayedTaskInfo(DelayedTaskInfo&&) = default;
tommif9d91542017-02-17 10:47:1186
tommi0b942152017-03-10 17:33:5387 // Implement for priority_queue.
88 bool operator>(const DelayedTaskInfo& other) const {
89 return due_time_ > other.due_time_;
90 }
tommif9d91542017-02-17 10:47:1191
tommi0b942152017-03-10 17:33:5392 // Required by priority_queue::pop().
93 DelayedTaskInfo& operator=(DelayedTaskInfo&& other) = default;
94
95 // See below for why this method is const.
96 void Run() const {
Danil Chapovalov3c06cfc2022-07-20 11:38:5897 RTC_DCHECK(task_);
98 std::move(task_)();
tommi0b942152017-03-10 17:33:5399 }
100
Danil Chapovalov3c06cfc2022-07-20 11:38:58101 Timestamp due_time() const { return due_time_; }
tommi0b942152017-03-10 17:33:53102
103 private:
Danil Chapovalov3c06cfc2022-07-20 11:38:58104 Timestamp due_time_ = Timestamp::Zero();
tommi0b942152017-03-10 17:33:53105
Artem Titov96e3b992021-07-26 14:03:14106 // `task` needs to be mutable because std::priority_queue::top() returns
tommi0b942152017-03-10 17:33:53107 // a const reference and a key in an ordered queue must not be changed.
108 // There are two basic workarounds, one using const_cast, which would also
Artem Titov96e3b992021-07-26 14:03:14109 // make the key (`due_time`), non-const and the other is to make the non-key
110 // (`task`), mutable.
111 // Because of this, the `task` variable is made private and can only be
112 // mutated by calling the `Run()` method.
Danil Chapovalov3c06cfc2022-07-20 11:38:58113 mutable absl::AnyInvocable<void() &&> task_;
tommi0b942152017-03-10 17:33:53114};
115
116class MultimediaTimer {
117 public:
tommi83722262017-03-15 11:36:29118 // Note: We create an event that requires manual reset.
119 MultimediaTimer() : event_(::CreateEvent(nullptr, true, false, nullptr)) {}
tommif9d91542017-02-17 10:47:11120
tommi0b942152017-03-10 17:33:53121 ~MultimediaTimer() {
122 Cancel();
123 ::CloseHandle(event_);
tommif9d91542017-02-17 10:47:11124 }
125
Artem Titov6cae2d52022-01-26 15:01:10126 MultimediaTimer(const MultimediaTimer&) = delete;
127 MultimediaTimer& operator=(const MultimediaTimer&) = delete;
128
tommi0b942152017-03-10 17:33:53129 bool StartOneShotTimer(UINT delay_ms) {
tommif9d91542017-02-17 10:47:11130 RTC_DCHECK_EQ(0, timer_id_);
131 RTC_DCHECK(event_ != nullptr);
tommif9d91542017-02-17 10:47:11132 timer_id_ =
133 ::timeSetEvent(delay_ms, 0, reinterpret_cast<LPTIMECALLBACK>(event_), 0,
134 TIME_ONESHOT | TIME_CALLBACK_EVENT_SET);
135 return timer_id_ != 0;
136 }
137
tommi0b942152017-03-10 17:33:53138 void Cancel() {
tommif9d91542017-02-17 10:47:11139 if (timer_id_) {
140 ::timeKillEvent(timer_id_);
141 timer_id_ = 0;
142 }
Danil Chapovalovfa733932020-01-13 11:56:13143 // Now that timer is killed and not able to set the event, reset the event.
144 // Doing it in opposite order is racy because event may be set between
145 // event was reset and timer is killed leaving MultimediaTimer in surprising
146 // state where both event is set and timer is canceled.
147 ::ResetEvent(event_);
tommif9d91542017-02-17 10:47:11148 }
149
tommi0b942152017-03-10 17:33:53150 HANDLE* event_for_wait() { return &event_; }
tommif9d91542017-02-17 10:47:11151
152 private:
tommif9d91542017-02-17 10:47:11153 HANDLE event_ = nullptr;
154 MMRESULT timer_id_ = 0;
tommif9d91542017-02-17 10:47:11155};
156
Danil Chapovalov826f2e72019-02-20 17:13:09157class TaskQueueWin : public TaskQueueBase {
tommi0b942152017-03-10 17:33:53158 public:
Danil Chapovalov826f2e72019-02-20 17:13:09159 TaskQueueWin(absl::string_view queue_name, rtc::ThreadPriority priority);
160 ~TaskQueueWin() override = default;
tommi0b942152017-03-10 17:33:53161
Danil Chapovalov826f2e72019-02-20 17:13:09162 void Delete() override;
Markus Handell2a256c82023-02-27 11:41:39163
164 protected:
165 void PostTaskImpl(absl::AnyInvocable<void() &&> task,
166 const PostTaskTraits& traits,
167 const Location& location) override;
168 void PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task,
169 TimeDelta delay,
170 const PostDelayedTaskTraits& traits,
171 const Location& location) override;
nisse341c8e402017-09-06 11:38:22172 void RunPendingTasks();
tommi0b942152017-03-10 17:33:53173
174 private:
Danil Chapovalov826f2e72019-02-20 17:13:09175 void RunThreadMain();
176 bool ProcessQueuedMessages();
177 void RunDueTasks();
178 void ScheduleNextTimer();
179 void CancelTimers();
nisse341c8e402017-09-06 11:38:22180
Danil Chapovalov3c06cfc2022-07-20 11:38:58181 MultimediaTimer timer_;
Danil Chapovalov826f2e72019-02-20 17:13:09182 // Since priority_queue<> by defult orders items in terms of
183 // largest->smallest, using std::less<>, and we want smallest->largest,
Danil Chapovalov3c06cfc2022-07-20 11:38:58184 // we would like to use std::greater<> here.
Danil Chapovalov826f2e72019-02-20 17:13:09185 std::priority_queue<DelayedTaskInfo,
186 std::vector<DelayedTaskInfo>,
Danil Chapovalov3c06cfc2022-07-20 11:38:58187 std::greater<DelayedTaskInfo>>
Danil Chapovalov826f2e72019-02-20 17:13:09188 timer_tasks_;
189 UINT_PTR timer_id_ = 0;
Markus Handellad5037b2021-05-07 13:02:36190 rtc::PlatformThread thread_;
Markus Handell18523c32020-07-08 15:55:58191 Mutex pending_lock_;
Danil Chapovalov3c06cfc2022-07-20 11:38:58192 std::queue<absl::AnyInvocable<void() &&>> pending_
danilchapa37de392017-09-09 11:17:22193 RTC_GUARDED_BY(pending_lock_);
tommi83722262017-03-15 11:36:29194 HANDLE in_queue_;
tommi0b942152017-03-10 17:33:53195};
196
Danil Chapovalov826f2e72019-02-20 17:13:09197TaskQueueWin::TaskQueueWin(absl::string_view queue_name,
198 rtc::ThreadPriority priority)
Markus Handellad5037b2021-05-07 13:02:36199 : in_queue_(::CreateEvent(nullptr, true, false, nullptr)) {
tommi83722262017-03-15 11:36:29200 RTC_DCHECK(in_queue_);
Markus Handellad5037b2021-05-07 13:02:36201 thread_ = rtc::PlatformThread::SpawnJoinable(
202 [this] { RunThreadMain(); }, queue_name,
203 rtc::ThreadAttributes().SetPriority(priority));
204
Danil Chapovalov826f2e72019-02-20 17:13:09205 rtc::Event event(false, false);
tommic06b1332016-05-14 18:31:40206 RTC_CHECK(thread_.QueueAPC(&InitializeQueueThread,
Danil Chapovalov826f2e72019-02-20 17:13:09207 reinterpret_cast<ULONG_PTR>(&event)));
208 event.Wait(rtc::Event::kForever);
tommic06b1332016-05-14 18:31:40209}
210
Danil Chapovalov826f2e72019-02-20 17:13:09211void TaskQueueWin::Delete() {
tommic06b1332016-05-14 18:31:40212 RTC_DCHECK(!IsCurrent());
Florent Castelli8037fc62024-08-29 13:00:40213 RTC_CHECK(thread_.GetHandle() != std::nullopt);
Markus Handellad5037b2021-05-07 13:02:36214 while (
215 !::PostThreadMessage(GetThreadId(*thread_.GetHandle()), WM_QUIT, 0, 0)) {
kwiberg352444f2016-11-28 23:58:53216 RTC_CHECK_EQ(ERROR_NOT_ENOUGH_QUOTA, ::GetLastError());
tommic06b1332016-05-14 18:31:40217 Sleep(1);
218 }
Markus Handellad5037b2021-05-07 13:02:36219 thread_.Finalize();
tommi83722262017-03-15 11:36:29220 ::CloseHandle(in_queue_);
Danil Chapovalov826f2e72019-02-20 17:13:09221 delete this;
tommic06b1332016-05-14 18:31:40222}
223
Markus Handell2a256c82023-02-27 11:41:39224void TaskQueueWin::PostTaskImpl(absl::AnyInvocable<void() &&> task,
225 const PostTaskTraits& traits,
226 const Location& location) {
Markus Handell18523c32020-07-08 15:55:58227 MutexLock lock(&pending_lock_);
tommi83722262017-03-15 11:36:29228 pending_.push(std::move(task));
229 ::SetEvent(in_queue_);
tommic06b1332016-05-14 18:31:40230}
231
Markus Handell2a256c82023-02-27 11:41:39232void TaskQueueWin::PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task,
233 TimeDelta delay,
234 const PostDelayedTaskTraits& traits,
235 const Location& location) {
Danil Chapovalov3c06cfc2022-07-20 11:38:58236 if (delay <= TimeDelta::Zero()) {
tommi0b942152017-03-10 17:33:53237 PostTask(std::move(task));
238 return;
239 }
240
Danil Chapovalov3c06cfc2022-07-20 11:38:58241 auto* task_info = new DelayedTaskInfo(delay, std::move(task));
Florent Castelli8037fc62024-08-29 13:00:40242 RTC_CHECK(thread_.GetHandle() != std::nullopt);
Markus Handellad5037b2021-05-07 13:02:36243 if (!::PostThreadMessage(GetThreadId(*thread_.GetHandle()),
244 WM_QUEUE_DELAYED_TASK, 0,
tommi0b942152017-03-10 17:33:53245 reinterpret_cast<LPARAM>(task_info))) {
246 delete task_info;
tommic06b1332016-05-14 18:31:40247 }
248}
249
Danil Chapovalov826f2e72019-02-20 17:13:09250void TaskQueueWin::RunPendingTasks() {
tommi83722262017-03-15 11:36:29251 while (true) {
Danil Chapovalov3c06cfc2022-07-20 11:38:58252 absl::AnyInvocable<void() &&> task;
tommi83722262017-03-15 11:36:29253 {
Markus Handell18523c32020-07-08 15:55:58254 MutexLock lock(&pending_lock_);
tommi83722262017-03-15 11:36:29255 if (pending_.empty())
256 break;
257 task = std::move(pending_.front());
258 pending_.pop();
259 }
260
Danil Chapovalov3c06cfc2022-07-20 11:38:58261 std::move(task)();
tommi83722262017-03-15 11:36:29262 }
263}
264
Danil Chapovalov826f2e72019-02-20 17:13:09265void TaskQueueWin::RunThreadMain() {
266 CurrentTaskQueueSetter set_current(this);
Yves Gerey665174f2018-06-19 13:03:05267 HANDLE handles[2] = {*timer_.event_for_wait(), in_queue_};
tommib89257a2016-07-12 08:24:36268 while (true) {
tommif9d91542017-02-17 10:47:11269 // Make sure we do an alertable wait as that's required to allow APCs to run
270 // (e.g. required for InitializeQueueThread and stopping the thread in
271 // PlatformThread).
tommi0b942152017-03-10 17:33:53272 DWORD result = ::MsgWaitForMultipleObjectsEx(
tommi83722262017-03-15 11:36:29273 arraysize(handles), handles, INFINITE, QS_ALLEVENTS, MWMO_ALERTABLE);
tommib89257a2016-07-12 08:24:36274 RTC_CHECK_NE(WAIT_FAILED, result);
tommi83722262017-03-15 11:36:29275 if (result == (WAIT_OBJECT_0 + 2)) {
tommi0b942152017-03-10 17:33:53276 // There are messages in the message queue that need to be handled.
277 if (!ProcessQueuedMessages())
tommib89257a2016-07-12 08:24:36278 break;
tommi83722262017-03-15 11:36:29279 }
280
Yves Gerey665174f2018-06-19 13:03:05281 if (result == WAIT_OBJECT_0 ||
282 (!timer_tasks_.empty() &&
283 ::WaitForSingleObject(*timer_.event_for_wait(), 0) == WAIT_OBJECT_0)) {
tommi0b942152017-03-10 17:33:53284 // The multimedia timer was signaled.
285 timer_.Cancel();
tommi0b942152017-03-10 17:33:53286 RunDueTasks();
287 ScheduleNextTimer();
tommi83722262017-03-15 11:36:29288 }
289
290 if (result == (WAIT_OBJECT_0 + 1)) {
291 ::ResetEvent(in_queue_);
Danil Chapovalov826f2e72019-02-20 17:13:09292 RunPendingTasks();
tommib89257a2016-07-12 08:24:36293 }
294 }
Markus Handell82da9322022-12-16 14:50:24295 // Ensure remaining deleted tasks are destroyed with Current() set up to this
296 // task queue.
297 std::queue<absl::AnyInvocable<void() &&>> pending;
298 {
299 MutexLock lock(&pending_lock_);
300 pending_.swap(pending);
301 }
302 pending = {};
303#if RTC_DCHECK_IS_ON
304 MutexLock lock(&pending_lock_);
305 RTC_DCHECK(pending_.empty());
306#endif
tommib89257a2016-07-12 08:24:36307}
tommic06b1332016-05-14 18:31:40308
Danil Chapovalov826f2e72019-02-20 17:13:09309bool TaskQueueWin::ProcessQueuedMessages() {
tommib89257a2016-07-12 08:24:36310 MSG msg = {};
tommi83722262017-03-15 11:36:29311 // To protect against overly busy message queues, we limit the time
312 // we process tasks to a few milliseconds. If we don't do that, there's
313 // a chance that timer tasks won't ever run.
Danil Chapovalov3c06cfc2022-07-20 11:38:58314 static constexpr TimeDelta kMaxTaskProcessingTime = TimeDelta::Millis(500);
315 Timestamp start = CurrentTime();
tommif9d91542017-02-17 10:47:11316 while (::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE) &&
tommib89257a2016-07-12 08:24:36317 msg.message != WM_QUIT) {
tommic06b1332016-05-14 18:31:40318 if (!msg.hwnd) {
319 switch (msg.message) {
tommic06b1332016-05-14 18:31:40320 case WM_QUEUE_DELAYED_TASK: {
tommi0b942152017-03-10 17:33:53321 std::unique_ptr<DelayedTaskInfo> info(
322 reinterpret_cast<DelayedTaskInfo*>(msg.lParam));
323 bool need_to_schedule_timers =
324 timer_tasks_.empty() ||
325 timer_tasks_.top().due_time() > info->due_time();
Danil Chapovalov3c06cfc2022-07-20 11:38:58326 timer_tasks_.push(std::move(*info));
tommi0b942152017-03-10 17:33:53327 if (need_to_schedule_timers) {
328 CancelTimers();
329 ScheduleNextTimer();
tommif9d91542017-02-17 10:47:11330 }
tommic06b1332016-05-14 18:31:40331 break;
332 }
333 case WM_TIMER: {
tommi0b942152017-03-10 17:33:53334 RTC_DCHECK_EQ(timer_id_, msg.wParam);
tommif9d91542017-02-17 10:47:11335 ::KillTimer(nullptr, msg.wParam);
tommi0b942152017-03-10 17:33:53336 timer_id_ = 0;
337 RunDueTasks();
338 ScheduleNextTimer();
tommic06b1332016-05-14 18:31:40339 break;
340 }
341 default:
Artem Titovd3251962021-11-15 15:57:07342 RTC_DCHECK_NOTREACHED();
tommic06b1332016-05-14 18:31:40343 break;
344 }
345 } else {
tommif9d91542017-02-17 10:47:11346 ::TranslateMessage(&msg);
347 ::DispatchMessage(&msg);
tommic06b1332016-05-14 18:31:40348 }
tommi83722262017-03-15 11:36:29349
Danil Chapovalov3c06cfc2022-07-20 11:38:58350 if (CurrentTime() > start + kMaxTaskProcessingTime)
tommi83722262017-03-15 11:36:29351 break;
tommic06b1332016-05-14 18:31:40352 }
tommib89257a2016-07-12 08:24:36353 return msg.message != WM_QUIT;
tommic06b1332016-05-14 18:31:40354}
tommib89257a2016-07-12 08:24:36355
Danil Chapovalov826f2e72019-02-20 17:13:09356void TaskQueueWin::RunDueTasks() {
tommi0b942152017-03-10 17:33:53357 RTC_DCHECK(!timer_tasks_.empty());
Danil Chapovalov3c06cfc2022-07-20 11:38:58358 Timestamp now = CurrentTime();
tommi0b942152017-03-10 17:33:53359 do {
360 const auto& top = timer_tasks_.top();
361 if (top.due_time() > now)
362 break;
363 top.Run();
364 timer_tasks_.pop();
365 } while (!timer_tasks_.empty());
366}
367
Danil Chapovalov826f2e72019-02-20 17:13:09368void TaskQueueWin::ScheduleNextTimer() {
tommi0b942152017-03-10 17:33:53369 RTC_DCHECK_EQ(timer_id_, 0);
370 if (timer_tasks_.empty())
371 return;
372
373 const auto& next_task = timer_tasks_.top();
Danil Chapovalov3c06cfc2022-07-20 11:38:58374 TimeDelta delay =
375 std::max(TimeDelta::Zero(), next_task.due_time() - CurrentTime());
376 uint32_t milliseconds = delay.RoundUpTo(TimeDelta::Millis(1)).ms<uint32_t>();
tommi0b942152017-03-10 17:33:53377 if (!timer_.StartOneShotTimer(milliseconds))
378 timer_id_ = ::SetTimer(nullptr, 0, milliseconds, nullptr);
379}
380
Danil Chapovalov826f2e72019-02-20 17:13:09381void TaskQueueWin::CancelTimers() {
tommi0b942152017-03-10 17:33:53382 timer_.Cancel();
383 if (timer_id_) {
384 ::KillTimer(nullptr, timer_id_);
385 timer_id_ = 0;
386 }
387}
388
Danil Chapovalov826f2e72019-02-20 17:13:09389class TaskQueueWinFactory : public TaskQueueFactory {
390 public:
391 std::unique_ptr<TaskQueueBase, TaskQueueDeleter> CreateTaskQueue(
392 absl::string_view name,
393 Priority priority) const override {
394 return std::unique_ptr<TaskQueueBase, TaskQueueDeleter>(
395 new TaskQueueWin(name, TaskQueuePriorityToThreadPriority(priority)));
396 }
397};
398
399} // namespace
400
401std::unique_ptr<TaskQueueFactory> CreateTaskQueueWinFactory() {
Mirko Bonadei317a1f02019-09-17 15:06:18402 return std::make_unique<TaskQueueWinFactory>();
nisse341c8e402017-09-06 11:38:22403}
404
Danil Chapovalov826f2e72019-02-20 17:13:09405} // namespace webrtc