Migrate gcd task queue implementation to TaskQueueBase interface
Bug: webrtc:10191 Change-Id: If15138f97445484668d3e42f3a35875521c38545 Reviewed-on: https://webrtc-review.googlesource.com/c/122501 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26782}
This commit is contained in:
committed by
Commit Bot
parent
f5d8808d93
commit
47cf5eaca4
@ -34,6 +34,7 @@ rtc_source_set("task_queue_factory") {
|
||||
":task_queue",
|
||||
"../../rtc_base:checks",
|
||||
"../../rtc_base:rtc_task_queue_api",
|
||||
"//third_party/abseil-cpp/absl/base:config",
|
||||
"//third_party/abseil-cpp/absl/base:core_headers",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
]
|
||||
@ -93,6 +94,11 @@ rtc_source_set("default_task_queue_factory_impl") {
|
||||
"default_task_queue_factory_libevent.cc",
|
||||
]
|
||||
deps += [ "../../rtc_base:rtc_task_queue_libevent" ]
|
||||
} else if (is_mac || is_ios) {
|
||||
sources = [
|
||||
"default_task_queue_factory_gcd.cc",
|
||||
]
|
||||
deps += [ "../../rtc_base:rtc_task_queue_gcd" ]
|
||||
} else {
|
||||
sources = [
|
||||
"default_task_queue_factory_unimplemented.cc",
|
||||
|
||||
21
api/task_queue/default_task_queue_factory_gcd.cc
Normal file
21
api/task_queue/default_task_queue_factory_gcd.cc
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2019 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "api/task_queue/task_queue_factory.h"
|
||||
#include "rtc_base/task_queue_gcd.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::unique_ptr<TaskQueueFactory> CreateDefaultTaskQueueFactory() {
|
||||
return CreateTaskQueueGcdFactory();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -10,6 +10,10 @@
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
#if defined(ABSL_HAVE_THREAD_LOCAL)
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
@ -31,5 +35,45 @@ TaskQueueBase::CurrentTaskQueueSetter::CurrentTaskQueueSetter(
|
||||
TaskQueueBase::CurrentTaskQueueSetter::~CurrentTaskQueueSetter() {
|
||||
current = previous_;
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
#elif defined(WEBRTC_POSIX)
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
ABSL_CONST_INIT pthread_key_t g_queue_ptr_tls = 0;
|
||||
|
||||
void InitializeTls() {
|
||||
RTC_CHECK(pthread_key_create(&g_queue_ptr_tls, nullptr) == 0);
|
||||
}
|
||||
|
||||
pthread_key_t GetQueuePtrTls() {
|
||||
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
||||
RTC_CHECK(pthread_once(&init_once, &InitializeTls) == 0);
|
||||
return g_queue_ptr_tls;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TaskQueueBase* TaskQueueBase::Current() {
|
||||
return static_cast<TaskQueueBase*>(pthread_getspecific(GetQueuePtrTls()));
|
||||
}
|
||||
|
||||
TaskQueueBase::CurrentTaskQueueSetter::CurrentTaskQueueSetter(
|
||||
TaskQueueBase* task_queue)
|
||||
: previous_(TaskQueueBase::Current()) {
|
||||
pthread_setspecific(GetQueuePtrTls(), task_queue);
|
||||
}
|
||||
|
||||
TaskQueueBase::CurrentTaskQueueSetter::~CurrentTaskQueueSetter() {
|
||||
pthread_setspecific(GetQueuePtrTls(), previous_);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#else
|
||||
#error Unsupported platform
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user