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}
This commit is contained in:
Niels Möller
2018-10-29 09:47:51 +01:00
committed by Commit Bot
parent 88d8d7d3f9
commit 2c16cc61c2
10 changed files with 74 additions and 101 deletions

View File

@ -35,6 +35,7 @@
#include "modules/audio_coding/neteq/tools/packet.h" #include "modules/audio_coding/neteq/tools/packet.h"
#include "modules/audio_coding/neteq/tools/rtp_file_source.h" #include "modules/audio_coding/neteq/tools/rtp_file_source.h"
#include "rtc_base/criticalsection.h" #include "rtc_base/criticalsection.h"
#include "rtc_base/event.h"
#include "rtc_base/messagedigest.h" #include "rtc_base/messagedigest.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
@ -42,7 +43,6 @@
#include "rtc_base/system/arch.h" #include "rtc_base/system/arch.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "system_wrappers/include/event_wrapper.h"
#include "system_wrappers/include/sleep.h" #include "system_wrappers/include/sleep.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/mock_audio_decoder.h" #include "test/mock_audio_decoder.h"
@ -481,7 +481,7 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
send_thread_(CbSendThread, this, "send"), send_thread_(CbSendThread, this, "send"),
insert_packet_thread_(CbInsertPacketThread, this, "insert_packet"), insert_packet_thread_(CbInsertPacketThread, this, "insert_packet"),
pull_audio_thread_(CbPullAudioThread, this, "pull_audio"), pull_audio_thread_(CbPullAudioThread, this, "pull_audio"),
test_complete_(EventWrapper::Create()), test_complete_(false, false),
send_count_(0), send_count_(0),
insert_packet_count_(0), insert_packet_count_(0),
pull_audio_count_(0), pull_audio_count_(0),
@ -512,8 +512,8 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
insert_packet_thread_.Stop(); insert_packet_thread_.Stop();
} }
EventTypeWrapper RunTest() { bool RunTest() {
return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. return test_complete_.Wait(10 * 60 * 1000); // 10 minutes' timeout.
} }
virtual bool TestDone() { virtual bool TestDone() {
@ -538,12 +538,12 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
SleepMs(1); SleepMs(1);
if (HasFatalFailure()) { if (HasFatalFailure()) {
// End the test early if a fatal failure (ASSERT_*) has occurred. // End the test early if a fatal failure (ASSERT_*) has occurred.
test_complete_->Set(); test_complete_.Set();
} }
++send_count_; ++send_count_;
InsertAudioAndVerifyEncoding(); InsertAudioAndVerifyEncoding();
if (TestDone()) { if (TestDone()) {
test_complete_->Set(); test_complete_.Set();
} }
return true; return true;
} }
@ -592,7 +592,7 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
rtc::PlatformThread send_thread_; rtc::PlatformThread send_thread_;
rtc::PlatformThread insert_packet_thread_; rtc::PlatformThread insert_packet_thread_;
rtc::PlatformThread pull_audio_thread_; rtc::PlatformThread pull_audio_thread_;
const std::unique_ptr<EventWrapper> test_complete_; rtc::Event test_complete_;
int send_count_; int send_count_;
int insert_packet_count_; int insert_packet_count_;
int pull_audio_count_ RTC_GUARDED_BY(crit_sect_); int pull_audio_count_ RTC_GUARDED_BY(crit_sect_);
@ -607,7 +607,7 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
#define MAYBE_DoTest DoTest #define MAYBE_DoTest DoTest
#endif #endif
TEST_F(AudioCodingModuleMtTestOldApi, MAYBE_DoTest) { TEST_F(AudioCodingModuleMtTestOldApi, MAYBE_DoTest) {
EXPECT_EQ(kEventSignaled, RunTest()); EXPECT_TRUE(RunTest());
} }
// This is a multi-threaded ACM test using iSAC. The test encodes audio // This is a multi-threaded ACM test using iSAC. The test encodes audio
@ -717,7 +717,7 @@ class AcmIsacMtTestOldApi : public AudioCodingModuleMtTestOldApi {
#endif #endif
#if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
TEST_F(AcmIsacMtTestOldApi, MAYBE_DoTest) { TEST_F(AcmIsacMtTestOldApi, MAYBE_DoTest) {
EXPECT_EQ(kEventSignaled, RunTest()); EXPECT_TRUE(RunTest());
} }
#endif #endif
@ -734,7 +734,7 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
codec_registration_thread_(CbCodecRegistrationThread, codec_registration_thread_(CbCodecRegistrationThread,
this, this,
"codec_registration"), "codec_registration"),
test_complete_(EventWrapper::Create()), test_complete_(false, false),
codec_registered_(false), codec_registered_(false),
receive_packet_count_(0), receive_packet_count_(0),
next_insert_packet_time_ms_(0), next_insert_packet_time_ms_(0),
@ -781,8 +781,8 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
codec_registration_thread_.Stop(); codec_registration_thread_.Stop();
} }
EventTypeWrapper RunTest() { bool RunTest() {
return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. return test_complete_.Wait(10 * 60 * 1000); // 10 minutes' timeout.
} }
static bool CbReceiveThread(void* context) { static bool CbReceiveThread(void* context) {
@ -845,7 +845,7 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
SleepMs(1); SleepMs(1);
if (HasFatalFailure()) { if (HasFatalFailure()) {
// End the test early if a fatal failure (ASSERT_*) has occurred. // End the test early if a fatal failure (ASSERT_*) has occurred.
test_complete_->Set(); test_complete_.Set();
} }
rtc::CritScope lock(&crit_sect_); rtc::CritScope lock(&crit_sect_);
if (!codec_registered_ && if (!codec_registered_ &&
@ -856,14 +856,14 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
codec_registered_ = true; codec_registered_ = true;
} }
if (codec_registered_ && receive_packet_count_ > kNumPackets) { if (codec_registered_ && receive_packet_count_ > kNumPackets) {
test_complete_->Set(); test_complete_.Set();
} }
return true; return true;
} }
rtc::PlatformThread receive_thread_; rtc::PlatformThread receive_thread_;
rtc::PlatformThread codec_registration_thread_; rtc::PlatformThread codec_registration_thread_;
const std::unique_ptr<EventWrapper> test_complete_; rtc::Event test_complete_;
rtc::CriticalSection crit_sect_; rtc::CriticalSection crit_sect_;
bool codec_registered_ RTC_GUARDED_BY(crit_sect_); bool codec_registered_ RTC_GUARDED_BY(crit_sect_);
int receive_packet_count_ RTC_GUARDED_BY(crit_sect_); int receive_packet_count_ RTC_GUARDED_BY(crit_sect_);
@ -880,7 +880,7 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
#endif #endif
#if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
TEST_F(AcmReRegisterIsacMtTestOldApi, MAYBE_DoTest) { TEST_F(AcmReRegisterIsacMtTestOldApi, MAYBE_DoTest) {
EXPECT_EQ(kEventSignaled, RunTest()); EXPECT_TRUE(RunTest());
} }
#endif #endif

View File

@ -26,7 +26,6 @@ class PlatformThread;
} // namespace rtc } // namespace rtc
namespace webrtc { namespace webrtc {
class EventWrapper;
// This is a fake audio device which plays audio from a file as its microphone // This is a fake audio device which plays audio from a file as its microphone
// and plays out into a file. // and plays out into a file.

View File

@ -29,7 +29,6 @@ typedef webrtc::adm_linux_alsa::AlsaSymbolTable WebRTCAlsaSymbolTable;
WebRTCAlsaSymbolTable* GetAlsaSymbolTable(); WebRTCAlsaSymbolTable* GetAlsaSymbolTable();
namespace webrtc { namespace webrtc {
class EventWrapper;
class AudioDeviceLinuxALSA : public AudioDeviceGeneric { class AudioDeviceLinuxALSA : public AudioDeviceGeneric {
public: public:

View File

@ -14,7 +14,6 @@
#include "modules/audio_device/linux/latebindingsymboltable_linux.h" #include "modules/audio_device/linux/latebindingsymboltable_linux.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "system_wrappers/include/event_wrapper.h"
WebRTCPulseSymbolTable* GetPulseSymbolTable() { WebRTCPulseSymbolTable* GetPulseSymbolTable() {
static WebRTCPulseSymbolTable* pulse_symbol_table = static WebRTCPulseSymbolTable* pulse_symbol_table =
@ -33,10 +32,10 @@ namespace webrtc {
AudioDeviceLinuxPulse::AudioDeviceLinuxPulse() AudioDeviceLinuxPulse::AudioDeviceLinuxPulse()
: _ptrAudioBuffer(NULL), : _ptrAudioBuffer(NULL),
_timeEventRec(*EventWrapper::Create()), _timeEventRec(false, false),
_timeEventPlay(*EventWrapper::Create()), _timeEventPlay(false, false),
_recStartEvent(*EventWrapper::Create()), _recStartEvent(false, false),
_playStartEvent(*EventWrapper::Create()), _playStartEvent(false, false),
_inputDeviceIndex(0), _inputDeviceIndex(0),
_outputDeviceIndex(0), _outputDeviceIndex(0),
_inputDeviceIsSpecified(false), _inputDeviceIsSpecified(false),
@ -113,11 +112,6 @@ AudioDeviceLinuxPulse::~AudioDeviceLinuxPulse() {
delete[] _recDeviceName; delete[] _recDeviceName;
_recDeviceName = NULL; _recDeviceName = NULL;
} }
delete &_recStartEvent;
delete &_playStartEvent;
delete &_timeEventRec;
delete &_timeEventPlay;
} }
void AudioDeviceLinuxPulse::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { void AudioDeviceLinuxPulse::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
@ -1067,7 +1061,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() {
// The audio thread will signal when recording has started. // The audio thread will signal when recording has started.
_timeEventRec.Set(); _timeEventRec.Set();
if (kEventTimeout == _recStartEvent.Wait(10000)) { if (!_recStartEvent.Wait(10000)) {
{ {
rtc::CritScope lock(&_critSect); rtc::CritScope lock(&_critSect);
_startRec = false; _startRec = false;
@ -1182,7 +1176,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
// The audio thread will signal when playout has started. // The audio thread will signal when playout has started.
_timeEventPlay.Set(); _timeEventPlay.Set();
if (kEventTimeout == _playStartEvent.Wait(10000)) { if (!_playStartEvent.Wait(10000)) {
{ {
rtc::CritScope lock(&_critSect); rtc::CritScope lock(&_critSect);
_startPlay = false; _startPlay = false;
@ -1996,13 +1990,7 @@ bool AudioDeviceLinuxPulse::RecThreadFunc(void* pThis) {
} }
bool AudioDeviceLinuxPulse::PlayThreadProcess() { bool AudioDeviceLinuxPulse::PlayThreadProcess() {
switch (_timeEventPlay.Wait(1000)) { if (!_timeEventPlay.Wait(1000)) {
case kEventSignaled:
break;
case kEventError:
RTC_LOG(LS_WARNING) << "EventWrapper::Wait() failed";
return true;
case kEventTimeout:
return true; return true;
} }
@ -2170,13 +2158,7 @@ bool AudioDeviceLinuxPulse::PlayThreadProcess() {
} }
bool AudioDeviceLinuxPulse::RecThreadProcess() { bool AudioDeviceLinuxPulse::RecThreadProcess() {
switch (_timeEventRec.Wait(1000)) { if (!_timeEventRec.Wait(1000)) {
case kEventSignaled:
break;
case kEventError:
RTC_LOG(LS_WARNING) << "EventWrapper::Wait() failed";
return true;
case kEventTimeout:
return true; return true;
} }

View File

@ -20,6 +20,7 @@
#include "modules/audio_device/linux/audio_mixer_manager_pulse_linux.h" #include "modules/audio_device/linux/audio_mixer_manager_pulse_linux.h"
#include "modules/audio_device/linux/pulseaudiosymboltable_linux.h" #include "modules/audio_device/linux/pulseaudiosymboltable_linux.h"
#include "rtc_base/criticalsection.h" #include "rtc_base/criticalsection.h"
#include "rtc_base/event.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
@ -103,7 +104,6 @@ typedef webrtc::adm_linux_pulse::PulseAudioSymbolTable WebRTCPulseSymbolTable;
WebRTCPulseSymbolTable* GetPulseSymbolTable(); WebRTCPulseSymbolTable* GetPulseSymbolTable();
namespace webrtc { namespace webrtc {
class EventWrapper;
class AudioDeviceLinuxPulse : public AudioDeviceGeneric { class AudioDeviceLinuxPulse : public AudioDeviceGeneric {
public: public:
@ -262,10 +262,10 @@ class AudioDeviceLinuxPulse : public AudioDeviceGeneric {
AudioDeviceBuffer* _ptrAudioBuffer; AudioDeviceBuffer* _ptrAudioBuffer;
rtc::CriticalSection _critSect; rtc::CriticalSection _critSect;
EventWrapper& _timeEventRec; rtc::Event _timeEventRec;
EventWrapper& _timeEventPlay; rtc::Event _timeEventPlay;
EventWrapper& _recStartEvent; rtc::Event _recStartEvent;
EventWrapper& _playStartEvent; rtc::Event _playStartEvent;
// TODO(pbos): Remove unique_ptr and use directly without resetting. // TODO(pbos): Remove unique_ptr and use directly without resetting.
std::unique_ptr<rtc::PlatformThread> _ptrThreadPlay; std::unique_ptr<rtc::PlatformThread> _ptrThreadPlay;

View File

@ -18,11 +18,11 @@
#include "api/array_view.h" #include "api/array_view.h"
#include "modules/audio_processing/test/test_utils.h" #include "modules/audio_processing/test/test_utils.h"
#include "rtc_base/atomicops.h" #include "rtc_base/atomicops.h"
#include "rtc_base/event.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/random.h" #include "rtc_base/random.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "system_wrappers/include/event_wrapper.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/perf_test.h" #include "test/testsupport/perf_test.h"
@ -391,7 +391,7 @@ class TimedThreadApiProcessor {
class CallSimulator : public ::testing::TestWithParam<SimulationConfig> { class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
public: public:
CallSimulator() CallSimulator()
: test_complete_(EventWrapper::Create()), : test_complete_(false, false),
render_thread_( render_thread_(
new rtc::PlatformThread(RenderProcessorThreadFunc, this, "render")), new rtc::PlatformThread(RenderProcessorThreadFunc, this, "render")),
capture_thread_(new rtc::PlatformThread(CaptureProcessorThreadFunc, capture_thread_(new rtc::PlatformThread(CaptureProcessorThreadFunc,
@ -401,10 +401,10 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
simulation_config_(static_cast<SimulationConfig>(GetParam())) {} simulation_config_(static_cast<SimulationConfig>(GetParam())) {}
// Run the call simulation with a timeout. // Run the call simulation with a timeout.
EventTypeWrapper Run() { bool Run() {
StartThreads(); StartThreads();
EventTypeWrapper result = test_complete_->Wait(kTestTimeout); bool result = test_complete_.Wait(kTestTimeout);
StopThreads(); StopThreads();
@ -420,7 +420,7 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
// done. // done.
bool MaybeEndTest() { bool MaybeEndTest() {
if (frame_counters_.BothCountersExceedeThreshold(kMinNumFramesToProcess)) { if (frame_counters_.BothCountersExceedeThreshold(kMinNumFramesToProcess)) {
test_complete_->Set(); test_complete_.Set();
return true; return true;
} }
return false; return false;
@ -570,7 +570,7 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
} }
// Event handler for the test. // Event handler for the test.
const std::unique_ptr<EventWrapper> test_complete_; rtc::Event test_complete_;
// Thread related variables. // Thread related variables.
std::unique_ptr<rtc::PlatformThread> render_thread_; std::unique_ptr<rtc::PlatformThread> render_thread_;
@ -619,7 +619,7 @@ const float CallSimulator::kCaptureInputFloatLevel = 0.03125f;
// TODO(peah): Reactivate once issue 7712 has been resolved. // TODO(peah): Reactivate once issue 7712 has been resolved.
TEST_P(CallSimulator, DISABLED_ApiCallDurationTest) { TEST_P(CallSimulator, DISABLED_ApiCallDurationTest) {
// Run test and verify that it did not time out. // Run test and verify that it did not time out.
EXPECT_EQ(kEventSignaled, Run()); EXPECT_TRUE(Run());
} }
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(

View File

@ -44,7 +44,7 @@ std::unique_ptr<ProcessThread> ProcessThread::Create(const char* thread_name) {
} }
ProcessThreadImpl::ProcessThreadImpl(const char* thread_name) ProcessThreadImpl::ProcessThreadImpl(const char* thread_name)
: wake_up_(EventWrapper::Create()), : wake_up_(/*manual_reset=*/false, /*initially_signaled=*/false),
stop_(false), stop_(false),
thread_name_(thread_name) {} thread_name_(thread_name) {}
@ -85,7 +85,7 @@ void ProcessThreadImpl::Stop() {
stop_ = true; stop_ = true;
} }
wake_up_->Set(); wake_up_.Set();
thread_->Stop(); thread_->Stop();
stop_ = false; stop_ = false;
@ -104,7 +104,7 @@ void ProcessThreadImpl::WakeUp(Module* module) {
m.next_callback = kCallProcessImmediately; m.next_callback = kCallProcessImmediately;
} }
} }
wake_up_->Set(); wake_up_.Set();
} }
void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) { void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) {
@ -113,7 +113,7 @@ void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) {
rtc::CritScope lock(&lock_); rtc::CritScope lock(&lock_);
queue_.push(task.release()); queue_.push(task.release());
} }
wake_up_->Set(); wake_up_.Set();
} }
void ProcessThreadImpl::RegisterModule(Module* module, void ProcessThreadImpl::RegisterModule(Module* module,
@ -147,7 +147,7 @@ void ProcessThreadImpl::RegisterModule(Module* module,
// Wake the thread calling ProcessThreadImpl::Process() to update the // Wake the thread calling ProcessThreadImpl::Process() to update the
// waiting time. The waiting time for the just registered module may be // waiting time. The waiting time for the just registered module may be
// shorter than all other registered modules. // shorter than all other registered modules.
wake_up_->Set(); wake_up_.Set();
} }
void ProcessThreadImpl::DeRegisterModule(Module* module) { void ProcessThreadImpl::DeRegisterModule(Module* module) {
@ -217,7 +217,7 @@ bool ProcessThreadImpl::Process() {
int64_t time_to_wait = next_checkpoint - rtc::TimeMillis(); int64_t time_to_wait = next_checkpoint - rtc::TimeMillis();
if (time_to_wait > 0) 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; return true;
} }

View File

@ -19,11 +19,11 @@
#include "modules/include/module.h" #include "modules/include/module.h"
#include "modules/utility/include/process_thread.h" #include "modules/utility/include/process_thread.h"
#include "rtc_base/criticalsection.h" #include "rtc_base/criticalsection.h"
#include "rtc_base/event.h"
#include "rtc_base/location.h" #include "rtc_base/location.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "system_wrappers/include/event_wrapper.h"
namespace webrtc { namespace webrtc {
@ -75,7 +75,7 @@ class ProcessThreadImpl : public ProcessThread {
rtc::CriticalSection lock_; // Used to guard modules_, tasks_ and stop_. rtc::CriticalSection lock_; // Used to guard modules_, tasks_ and stop_.
rtc::ThreadChecker thread_checker_; 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. // TODO(pbos): Remove unique_ptr and stop recreating the thread.
std::unique_ptr<rtc::PlatformThread> thread_; std::unique_ptr<rtc::PlatformThread> thread_;

View File

@ -42,14 +42,14 @@ class MockModule : public Module {
class RaiseEventTask : public rtc::QueuedTask { class RaiseEventTask : public rtc::QueuedTask {
public: public:
RaiseEventTask(EventWrapper* event) : event_(event) {} RaiseEventTask(rtc::Event* event) : event_(event) {}
bool Run() override { bool Run() override {
event_->Set(); event_->Set();
return true; return true;
} }
private: private:
EventWrapper* event_; rtc::Event* event_;
}; };
ACTION_P(SetEvent, event) { ACTION_P(SetEvent, event) {
@ -83,19 +83,19 @@ TEST(ProcessThreadImpl, ProcessCall) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
thread.Start(); thread.Start();
std::unique_ptr<EventWrapper> event(EventWrapper::Create()); rtc::Event event(false, false);
MockModule module; MockModule module;
EXPECT_CALL(module, TimeUntilNextProcess()) EXPECT_CALL(module, TimeUntilNextProcess())
.WillOnce(Return(0)) .WillOnce(Return(0))
.WillRepeatedly(Return(1)); .WillRepeatedly(Return(1));
EXPECT_CALL(module, Process()) EXPECT_CALL(module, Process())
.WillOnce(DoAll(SetEvent(event.get()), Return())) .WillOnce(DoAll(SetEvent(&event), Return()))
.WillRepeatedly(Return()); .WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE); thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop(); thread.Stop();
@ -105,21 +105,21 @@ TEST(ProcessThreadImpl, ProcessCall) {
// call to Start(). // call to Start().
TEST(ProcessThreadImpl, ProcessCall2) { TEST(ProcessThreadImpl, ProcessCall2) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
std::unique_ptr<EventWrapper> event(EventWrapper::Create()); rtc::Event event(false, false);
MockModule module; MockModule module;
EXPECT_CALL(module, TimeUntilNextProcess()) EXPECT_CALL(module, TimeUntilNextProcess())
.WillOnce(Return(0)) .WillOnce(Return(0))
.WillRepeatedly(Return(1)); .WillRepeatedly(Return(1));
EXPECT_CALL(module, Process()) EXPECT_CALL(module, Process())
.WillOnce(DoAll(SetEvent(event.get()), Return())) .WillOnce(DoAll(SetEvent(&event), Return()))
.WillRepeatedly(Return()); .WillRepeatedly(Return());
thread.RegisterModule(&module, RTC_FROM_HERE); thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start(); thread.Start();
EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop(); thread.Stop();
@ -129,7 +129,7 @@ TEST(ProcessThreadImpl, ProcessCall2) {
// After unregistration, we should not receive any further callbacks. // After unregistration, we should not receive any further callbacks.
TEST(ProcessThreadImpl, Deregister) { TEST(ProcessThreadImpl, Deregister) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
std::unique_ptr<EventWrapper> event(EventWrapper::Create()); rtc::Event event(false, false);
int process_count = 0; int process_count = 0;
MockModule module; MockModule module;
@ -137,8 +137,7 @@ TEST(ProcessThreadImpl, Deregister) {
.WillOnce(Return(0)) .WillOnce(Return(0))
.WillRepeatedly(Return(1)); .WillRepeatedly(Return(1));
EXPECT_CALL(module, Process()) EXPECT_CALL(module, Process())
.WillOnce( .WillOnce(DoAll(SetEvent(&event), Increment(&process_count), Return()))
DoAll(SetEvent(event.get()), Increment(&process_count), Return()))
.WillRepeatedly(DoAll(Increment(&process_count), Return())); .WillRepeatedly(DoAll(Increment(&process_count), Return()));
thread.RegisterModule(&module, RTC_FROM_HERE); thread.RegisterModule(&module, RTC_FROM_HERE);
@ -146,7 +145,7 @@ TEST(ProcessThreadImpl, Deregister) {
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start(); thread.Start();
EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); EXPECT_TRUE(event.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.DeRegisterModule(&module); thread.DeRegisterModule(&module);
@ -155,7 +154,7 @@ TEST(ProcessThreadImpl, Deregister) {
int count_after_deregister = process_count; int count_after_deregister = process_count;
// We shouldn't get any more callbacks. // 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); EXPECT_EQ(count_after_deregister, process_count);
thread.Stop(); thread.Stop();
} }
@ -167,7 +166,7 @@ void ProcessCallAfterAFewMs(int64_t milliseconds) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
thread.Start(); thread.Start();
std::unique_ptr<EventWrapper> event(EventWrapper::Create()); rtc::Event event(false, false);
MockModule module; MockModule module;
int64_t start_time = 0; int64_t start_time = 0;
@ -176,8 +175,7 @@ void ProcessCallAfterAFewMs(int64_t milliseconds) {
.WillOnce(DoAll(SetTimestamp(&start_time), Return(milliseconds))) .WillOnce(DoAll(SetTimestamp(&start_time), Return(milliseconds)))
.WillRepeatedly(Return(milliseconds)); .WillRepeatedly(Return(milliseconds));
EXPECT_CALL(module, Process()) EXPECT_CALL(module, Process())
.WillOnce( .WillOnce(DoAll(SetTimestamp(&called_time), SetEvent(&event), Return()))
DoAll(SetTimestamp(&called_time), SetEvent(event.get()), Return()))
.WillRepeatedly(Return()); .WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
@ -185,7 +183,7 @@ void ProcessCallAfterAFewMs(int64_t milliseconds) {
// Add a buffer of 50ms due to slowness of some trybots // Add a buffer of 50ms due to slowness of some trybots
// (e.g. win_drmemory_light) // (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); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop(); thread.Stop();
@ -230,7 +228,7 @@ TEST(ProcessThreadImpl, DISABLED_Process50Times) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
thread.Start(); thread.Start();
std::unique_ptr<EventWrapper> event(EventWrapper::Create()); rtc::Event event(false, false);
MockModule module; MockModule module;
int callback_count = 0; int callback_count = 0;
@ -242,7 +240,7 @@ TEST(ProcessThreadImpl, DISABLED_Process50Times) {
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE); thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventTimeout, event->Wait(1000)); EXPECT_TRUE(event.Wait(1000));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop(); thread.Stop();
@ -261,8 +259,8 @@ TEST(ProcessThreadImpl, WakeUp) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
thread.Start(); thread.Start();
std::unique_ptr<EventWrapper> started(EventWrapper::Create()); rtc::Event started(false, false);
std::unique_ptr<EventWrapper> called(EventWrapper::Create()); rtc::Event called(false, false);
MockModule module; MockModule module;
int64_t start_time; int64_t start_time;
@ -276,20 +274,19 @@ TEST(ProcessThreadImpl, WakeUp) {
// The second time TimeUntilNextProcess is then called, is after Process // The second time TimeUntilNextProcess is then called, is after Process
// has been called and we don't expect any more calls. // has been called and we don't expect any more calls.
EXPECT_CALL(module, TimeUntilNextProcess()) EXPECT_CALL(module, TimeUntilNextProcess())
.WillOnce(DoAll(SetTimestamp(&start_time), SetEvent(started.get()), .WillOnce(
Return(1000))) DoAll(SetTimestamp(&start_time), SetEvent(&started), Return(1000)))
.WillOnce(Return(1000)); .WillOnce(Return(1000));
EXPECT_CALL(module, Process()) EXPECT_CALL(module, Process())
.WillOnce( .WillOnce(DoAll(SetTimestamp(&called_time), SetEvent(&called), Return()))
DoAll(SetTimestamp(&called_time), SetEvent(called.get()), Return()))
.WillRepeatedly(Return()); .WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.RegisterModule(&module, RTC_FROM_HERE); thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventSignaled, started->Wait(kEventWaitTimeout)); EXPECT_TRUE(started.Wait(kEventWaitTimeout));
thread.WakeUp(&module); thread.WakeUp(&module);
EXPECT_EQ(kEventSignaled, called->Wait(kEventWaitTimeout)); EXPECT_TRUE(called.Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
thread.Stop(); thread.Stop();
@ -304,11 +301,11 @@ TEST(ProcessThreadImpl, WakeUp) {
// thread. // thread.
TEST(ProcessThreadImpl, PostTask) { TEST(ProcessThreadImpl, PostTask) {
ProcessThreadImpl thread("ProcessThread"); ProcessThreadImpl thread("ProcessThread");
std::unique_ptr<EventWrapper> task_ran(EventWrapper::Create()); rtc::Event task_ran(false, false);
std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(&task_ran));
thread.Start(); thread.Start();
thread.PostTask(std::move(task)); thread.PostTask(std::move(task));
EXPECT_EQ(kEventSignaled, task_ran->Wait(kEventWaitTimeout)); EXPECT_TRUE(task_ran.Wait(kEventWaitTimeout));
thread.Stop(); thread.Stop();
} }

View File

@ -12,11 +12,7 @@
#define SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ #define SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_
namespace webrtc { namespace webrtc {
enum EventTypeWrapper { enum EventTypeWrapper { kEventSignaled = 1, kEventTimeout = 2 };
kEventSignaled = 1,
kEventError = 2,
kEventTimeout = 3
};
#define WEBRTC_EVENT_INFINITE 0xffffffff #define WEBRTC_EVENT_INFINITE 0xffffffff