Replace some usage of EventWrapper with rtc::Event.
Bug: webrtc:3380
Change-Id: Id33b19bf107273e6f838aa633784db73d02ae2c2
Reviewed-on: https://webrtc-review.googlesource.com/c/107888
Reviewed-by: Henrik Grunell <henrikg@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25407}
diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc
index 9756250..73338ac 100644
--- a/modules/utility/source/process_thread_impl.cc
+++ b/modules/utility/source/process_thread_impl.cc
@@ -44,7 +44,7 @@
}
ProcessThreadImpl::ProcessThreadImpl(const char* thread_name)
- : wake_up_(EventWrapper::Create()),
+ : wake_up_(/*manual_reset=*/false, /*initially_signaled=*/false),
stop_(false),
thread_name_(thread_name) {}
@@ -85,7 +85,7 @@
stop_ = true;
}
- wake_up_->Set();
+ wake_up_.Set();
thread_->Stop();
stop_ = false;
@@ -104,7 +104,7 @@
m.next_callback = kCallProcessImmediately;
}
}
- wake_up_->Set();
+ wake_up_.Set();
}
void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) {
@@ -113,7 +113,7 @@
rtc::CritScope lock(&lock_);
queue_.push(task.release());
}
- wake_up_->Set();
+ wake_up_.Set();
}
void ProcessThreadImpl::RegisterModule(Module* module,
@@ -147,7 +147,7 @@
// Wake the thread calling ProcessThreadImpl::Process() to update the
// waiting time. The waiting time for the just registered module may be
// shorter than all other registered modules.
- wake_up_->Set();
+ wake_up_.Set();
}
void ProcessThreadImpl::DeRegisterModule(Module* module) {
@@ -217,7 +217,7 @@
int64_t time_to_wait = next_checkpoint - rtc::TimeMillis();
if (time_to_wait > 0)
- wake_up_->Wait(static_cast<unsigned long>(time_to_wait));
+ wake_up_.Wait(static_cast<int>(time_to_wait));
return true;
}
diff --git a/modules/utility/source/process_thread_impl.h b/modules/utility/source/process_thread_impl.h
index 6f119d4..fff21d0 100644
--- a/modules/utility/source/process_thread_impl.h
+++ b/modules/utility/source/process_thread_impl.h
@@ -19,11 +19,11 @@
#include "modules/include/module.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/criticalsection.h"
+#include "rtc_base/event.h"
#include "rtc_base/location.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h"
-#include "system_wrappers/include/event_wrapper.h"
namespace webrtc {
@@ -75,7 +75,7 @@
rtc::CriticalSection lock_; // Used to guard modules_, tasks_ and stop_.
rtc::ThreadChecker thread_checker_;
- const std::unique_ptr<EventWrapper> wake_up_;
+ rtc::Event wake_up_;
// TODO(pbos): Remove unique_ptr and stop recreating the thread.
std::unique_ptr<rtc::PlatformThread> thread_;
diff --git a/modules/utility/source/process_thread_impl_unittest.cc b/modules/utility/source/process_thread_impl_unittest.cc
index d5926b2..730ea94 100644
--- a/modules/utility/source/process_thread_impl_unittest.cc
+++ b/modules/utility/source/process_thread_impl_unittest.cc
@@ -42,14 +42,14 @@
class RaiseEventTask : public rtc::QueuedTask {
public:
- RaiseEventTask(EventWrapper* event) : event_(event) {}
+ RaiseEventTask(rtc::Event* event) : event_(event) {}
bool Run() override {
event_->Set();
return true;
}
private:
- EventWrapper* event_;
+ rtc::Event* event_;
};
ACTION_P(SetEvent, event) {
@@ -83,19 +83,19 @@
ProcessThreadImpl thread("ProcessThread");
thread.Start();
- std::unique_ptr<EventWrapper> event(EventWrapper::Create());
+ rtc::Event event(false, false);
MockModule module;
EXPECT_CALL(module, TimeUntilNextProcess())
.WillOnce(Return(0))
.WillRepeatedly(Return(1));
EXPECT_CALL(module, Process())
- .WillOnce(DoAll(SetEvent(event.get()), Return()))
+ .WillOnce(DoAll(SetEvent(&event), Return()))
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE);
- EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop();
@@ -105,21 +105,21 @@
// call to Start().
TEST(ProcessThreadImpl, ProcessCall2) {
ProcessThreadImpl thread("ProcessThread");
- std::unique_ptr<EventWrapper> event(EventWrapper::Create());
+ rtc::Event event(false, false);
MockModule module;
EXPECT_CALL(module, TimeUntilNextProcess())
.WillOnce(Return(0))
.WillRepeatedly(Return(1));
EXPECT_CALL(module, Process())
- .WillOnce(DoAll(SetEvent(event.get()), Return()))
+ .WillOnce(DoAll(SetEvent(&event), Return()))
.WillRepeatedly(Return());
thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start();
- EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop();
@@ -129,7 +129,7 @@
// After unregistration, we should not receive any further callbacks.
TEST(ProcessThreadImpl, Deregister) {
ProcessThreadImpl thread("ProcessThread");
- std::unique_ptr<EventWrapper> event(EventWrapper::Create());
+ rtc::Event event(false, false);
int process_count = 0;
MockModule module;
@@ -137,8 +137,7 @@
.WillOnce(Return(0))
.WillRepeatedly(Return(1));
EXPECT_CALL(module, Process())
- .WillOnce(
- DoAll(SetEvent(event.get()), Increment(&process_count), Return()))
+ .WillOnce(DoAll(SetEvent(&event), Increment(&process_count), Return()))
.WillRepeatedly(DoAll(Increment(&process_count), Return()));
thread.RegisterModule(&module, RTC_FROM_HERE);
@@ -146,7 +145,7 @@
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start();
- EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.DeRegisterModule(&module);
@@ -155,7 +154,7 @@
int count_after_deregister = process_count;
// We shouldn't get any more callbacks.
- EXPECT_EQ(kEventTimeout, event->Wait(20));
+ EXPECT_FALSE(event.Wait(20));
EXPECT_EQ(count_after_deregister, process_count);
thread.Stop();
}
@@ -167,7 +166,7 @@
ProcessThreadImpl thread("ProcessThread");
thread.Start();
- std::unique_ptr<EventWrapper> event(EventWrapper::Create());
+ rtc::Event event(false, false);
MockModule module;
int64_t start_time = 0;
@@ -176,8 +175,7 @@
.WillOnce(DoAll(SetTimestamp(&start_time), Return(milliseconds)))
.WillRepeatedly(Return(milliseconds));
EXPECT_CALL(module, Process())
- .WillOnce(
- DoAll(SetTimestamp(&called_time), SetEvent(event.get()), Return()))
+ .WillOnce(DoAll(SetTimestamp(&called_time), SetEvent(&event), Return()))
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
@@ -185,7 +183,7 @@
// Add a buffer of 50ms due to slowness of some trybots
// (e.g. win_drmemory_light)
- EXPECT_EQ(kEventSignaled, event->Wait(milliseconds + 50));
+ EXPECT_TRUE(event.Wait(milliseconds + 50));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop();
@@ -230,7 +228,7 @@
ProcessThreadImpl thread("ProcessThread");
thread.Start();
- std::unique_ptr<EventWrapper> event(EventWrapper::Create());
+ rtc::Event event(false, false);
MockModule module;
int callback_count = 0;
@@ -242,7 +240,7 @@
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE);
- EXPECT_EQ(kEventTimeout, event->Wait(1000));
+ EXPECT_TRUE(event.Wait(1000));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop();
@@ -261,8 +259,8 @@
ProcessThreadImpl thread("ProcessThread");
thread.Start();
- std::unique_ptr<EventWrapper> started(EventWrapper::Create());
- std::unique_ptr<EventWrapper> called(EventWrapper::Create());
+ rtc::Event started(false, false);
+ rtc::Event called(false, false);
MockModule module;
int64_t start_time;
@@ -276,20 +274,19 @@
// The second time TimeUntilNextProcess is then called, is after Process
// has been called and we don't expect any more calls.
EXPECT_CALL(module, TimeUntilNextProcess())
- .WillOnce(DoAll(SetTimestamp(&start_time), SetEvent(started.get()),
- Return(1000)))
+ .WillOnce(
+ DoAll(SetTimestamp(&start_time), SetEvent(&started), Return(1000)))
.WillOnce(Return(1000));
EXPECT_CALL(module, Process())
- .WillOnce(
- DoAll(SetTimestamp(&called_time), SetEvent(called.get()), Return()))
+ .WillOnce(DoAll(SetTimestamp(&called_time), SetEvent(&called), Return()))
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE);
- EXPECT_EQ(kEventSignaled, started->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(started.Wait(kEventWaitTimeout));
thread.WakeUp(&module);
- EXPECT_EQ(kEventSignaled, called->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(called.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop();
@@ -304,11 +301,11 @@
// thread.
TEST(ProcessThreadImpl, PostTask) {
ProcessThreadImpl thread("ProcessThread");
- std::unique_ptr<EventWrapper> task_ran(EventWrapper::Create());
- std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
+ rtc::Event task_ran(false, false);
+ std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(&task_ran));
thread.Start();
thread.PostTask(std::move(task));
- EXPECT_EQ(kEventSignaled, task_ran->Wait(kEventWaitTimeout));
+ EXPECT_TRUE(task_ran.Wait(kEventWaitTimeout));
thread.Stop();
}