Skip to content

Commit

Permalink
This cl refactor TaskQueues to use a PIMPL implementation on linux/An…
Browse files Browse the repository at this point in the history
…droid.

In later steps the Win/Mac implementation will also be refactored.

The rtc_task_queue target is split up in three separate targets:

rtc_task_queue_api:
Contains the header file task_queue.h but no implementation.
Only external TaskQueue implementations should directly depend on this target.

rtc_task_queue_impl:
Contains the default implementation of task_queue.h.
Only external application targets should directly depend on this target.

rtc_task_queue:
WebRTC targets should depend on this target. It unconditionally depend on rtc_task_queue_api and depending on the new build flag,|rtc_link_task_queue_impl|,  depend on rtc_task_queue_impl.

BUG=webrtc:8160

Review-Url: https://codereview.webrtc.org/3003643002
Cr-Commit-Position: refs/heads/master@{#19516}
  • Loading branch information
perkj authored and Commit Bot committed Aug 25, 2017
1 parent ee95f87 commit 650fdae
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 82 deletions.
49 changes: 39 additions & 10 deletions webrtc/rtc_base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -295,42 +295,71 @@ config("enable_libevent_config") {
defines = [ "WEBRTC_BUILD_LIBEVENT" ]
}

rtc_static_library("rtc_task_queue") {
rtc_source_set("rtc_task_queue") {
public_deps = [
":rtc_base_approved",
":rtc_task_queue_api",
]

if (rtc_link_task_queue_impl) {
deps = [
":rtc_task_queue_impl",
]
}
}

# WebRTC targets must not directly depend on rtc_task_queue_api or
# rtc_task_queue_impl. Instead, depend on rtc_task_queue.
# The build flag |rtc_link_task_queue_impl| decides if WebRTC targets will link
# to the default implemenation in rtc_task_queue_impl or if an externally
# provided implementation should be used. An external implementation should
# depend on rtc_task_queue_api.
rtc_source_set("rtc_task_queue_api") {
if (build_with_chromium) {
sources = [
"../../webrtc_overrides/webrtc/rtc_base/task_queue.cc",
"../../webrtc_overrides/webrtc/rtc_base/task_queue.h",
]
} else {
sources = [
"task_queue.h",
"task_queue_posix.h",
]
}
deps = [
":rtc_base_approved",
]
}

rtc_source_set("rtc_task_queue_impl") {
deps = [
":rtc_base_approved",
":rtc_task_queue_api",
]
if (build_with_chromium) {
sources = [
"../../webrtc_overrides/webrtc/rtc_base/task_queue.cc",
]
} else {
if (rtc_build_libevent) {
deps = [
"//base/third_party/libevent",
]
deps += [ "//base/third_party/libevent" ]
}

if (rtc_enable_libevent) {
sources += [
sources = [
"task_queue_libevent.cc",
"task_queue_posix.cc",
"task_queue_posix.h",
]
all_dependent_configs = [ ":enable_libevent_config" ]
} else {
if (is_mac || is_ios) {
sources += [
sources = [
"task_queue_gcd.cc",
"task_queue_posix.cc",
]
}
if (is_win) {
sources += [ "task_queue_win.cc" ]
sources = [
"task_queue_win.cc",
]
}
}
}
Expand Down
43 changes: 6 additions & 37 deletions webrtc/rtc_base/task_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@
#include <memory>
#include <queue>

#if defined(WEBRTC_MAC) && !defined(WEBRTC_BUILD_LIBEVENT)
#if defined(WEBRTC_MAC)
#include <dispatch/dispatch.h>
#endif

#include "webrtc/rtc_base/constructormagic.h"
#include "webrtc/rtc_base/criticalsection.h"

#if defined(WEBRTC_WIN) || defined(WEBRTC_BUILD_LIBEVENT)
#include "webrtc/rtc_base/platform_thread.h"
#endif

#if defined(WEBRTC_BUILD_LIBEVENT)
#include "webrtc/rtc_base/refcountedobject.h"
#include "webrtc/rtc_base/scoped_ref_ptr.h"

struct event_base;
struct event;
#if defined(WEBRTC_WIN)
#include "webrtc/rtc_base/platform_thread.h"
#endif

namespace rtc {
Expand Down Expand Up @@ -242,32 +235,7 @@ class LOCKABLE TaskQueue {
}

private:
#if defined(WEBRTC_BUILD_LIBEVENT)
static void ThreadMain(void* context);
static void OnWakeup(int socket, short flags, void* context); // NOLINT
static void RunTask(int fd, short flags, void* context); // NOLINT
static void RunTimer(int fd, short flags, void* context); // NOLINT

class ReplyTaskOwner;
class PostAndReplyTask;
class SetTimerTask;

typedef RefCountedObject<ReplyTaskOwner> ReplyTaskOwnerRef;

void PrepareReplyTask(scoped_refptr<ReplyTaskOwnerRef> reply_task);

struct QueueContext;

int wakeup_pipe_in_ = -1;
int wakeup_pipe_out_ = -1;
event_base* event_base_;
std::unique_ptr<event> wakeup_event_;
PlatformThread thread_;
rtc::CriticalSection pending_lock_;
std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
std::list<scoped_refptr<ReplyTaskOwnerRef>> pending_replies_
GUARDED_BY(pending_lock_);
#elif defined(WEBRTC_MAC)
#if defined(WEBRTC_MAC)
struct QueueContext;
struct TaskContext;
struct PostTaskAndReplyContext;
Expand Down Expand Up @@ -295,7 +263,8 @@ class LOCKABLE TaskQueue {
std::queue<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
HANDLE in_queue_;
#else
#error not supported.
class Impl;
const scoped_refptr<Impl> impl_;
#endif

RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue);
Expand Down
Loading

0 comments on commit 650fdae

Please sign in to comment.