Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: webrtc/base/task_queue_libevent.cc

Issue 2147973002: Update on my last compatibility fix for libevent2. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/task_queue_libevent.cc
diff --git a/webrtc/base/task_queue_libevent.cc b/webrtc/base/task_queue_libevent.cc
index 94848f3c349fa6748347dc5a461bcbee44c2f62b..f3ab89be806984d87a7e604abb7189b665ef37f0 100644
--- a/webrtc/base/task_queue_libevent.cc
+++ b/webrtc/base/task_queue_libevent.cc
@@ -41,6 +41,26 @@ bool SetNonBlocking(int fd) {
RTC_CHECK(flags != -1);
return (flags & O_NONBLOCK) || fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1;
}
+
+// TODO(tommi): This is a hack to support two versions of libevent that we're
+// compatible with. The method we really want to call is event_assign(),
+// since event_set() has been marked as deprecated (and doesn't accept
+// passing event_base__ as a parameter). However, the version of libevent
+// that we have in Chromium, doesn't have event_assign(), so we need to call
+// event_set() there.
+void EventAssign(struct event* ev,
+ struct event_base* base,
+ int fd,
+ short events,
+ void (*callback)(int, short, void*),
+ void* arg) {
+#if defined(_EVENT2_EVENT_H_)
+ RTC_CHECK_EQ(0, event_assign(ev, base, fd, events, callback, arg));
+#else
+ event_set(ev, fd, events, callback, arg);
+ RTC_CHECK_EQ(0, event_base_set(base, ev));
+#endif
+}
} // namespace
struct TaskQueue::QueueContext {
@@ -124,20 +144,8 @@ TaskQueue::TaskQueue(const char* queue_name)
SetNonBlocking(fds[1]);
wakeup_pipe_out_ = fds[0];
wakeup_pipe_in_ = fds[1];
- // TODO(tommi): This is a hack to support two versions of libevent that we're
- // compatible with. The method we really want to call is event_assign(),
- // since event_set() has been marked as deprecated (and doesn't accept
- // passing event_base__ as a parameter). However, the version of libevent
- // that we have in Chromium, doesn't have event_assign(), so we need to call
- // event_set() there.
-#if defined(_EVENT2_EVENT_H_)
- event_assign(wakeup_event_.get(), event_base_, wakeup_pipe_out_,
- EV_READ | EV_PERSIST, OnWakeup, this);
-#else
- event_set(wakeup_event_.get(), wakeup_pipe_out_, EV_READ | EV_PERSIST,
- OnWakeup, this);
-#endif
- event_base_set(event_base_, wakeup_event_.get());
+ EventAssign(wakeup_event_.get(), event_base_, wakeup_pipe_out_,
+ EV_READ | EV_PERSIST, OnWakeup, this);
event_add(wakeup_event_.get(), 0);
thread_.Start();
}
@@ -222,8 +230,7 @@ void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
uint32_t milliseconds) {
if (IsCurrent()) {
TimerEvent* timer = new TimerEvent(std::move(task));
- evtimer_set(&timer->ev, &TaskQueue::RunTimer, timer);
- event_base_set(event_base_, &timer->ev);
+ EventAssign(&timer->ev, event_base_, -1, 0, &TaskQueue::RunTimer, timer);
QueueContext* ctx =
static_cast<QueueContext*>(pthread_getspecific(GetQueuePtrTls()));
ctx->pending_timers_.push_back(timer);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698