Clean up PlatformThread.

* Move PlatformThread to rtc::.
* Remove ::CreateThread factory method.
* Make non-scoped_ptr from a lot of invocations.
* Make Start/Stop void.
* Remove rtc::Thread priorities, which were unused and would collide.
* Add ::IsRunning() to PlatformThread.

BUG=
R=tommi@webrtc.org

Review URL: https://codereview.webrtc.org/1476453002 .

Cr-Commit-Position: refs/heads/master@{#10812}
This commit is contained in:
Peter Boström
2015-11-26 17:45:47 +01:00
parent ad113e50d2
commit 8c38e8b9b9
74 changed files with 374 additions and 1052 deletions

View File

@ -457,13 +457,9 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
AudioCodingModuleMtTestOldApi()
: AudioCodingModuleTestOldApi(),
send_thread_(PlatformThread::CreateThread(CbSendThread, this, "send")),
insert_packet_thread_(PlatformThread::CreateThread(CbInsertPacketThread,
this,
"insert_packet")),
pull_audio_thread_(PlatformThread::CreateThread(CbPullAudioThread,
this,
"pull_audio")),
send_thread_(CbSendThread, this, "send"),
insert_packet_thread_(CbInsertPacketThread, this, "insert_packet"),
pull_audio_thread_(CbPullAudioThread, this, "pull_audio"),
test_complete_(EventWrapper::Create()),
send_count_(0),
insert_packet_count_(0),
@ -481,19 +477,19 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
}
void StartThreads() {
ASSERT_TRUE(send_thread_->Start());
send_thread_->SetPriority(kRealtimePriority);
ASSERT_TRUE(insert_packet_thread_->Start());
insert_packet_thread_->SetPriority(kRealtimePriority);
ASSERT_TRUE(pull_audio_thread_->Start());
pull_audio_thread_->SetPriority(kRealtimePriority);
send_thread_.Start();
send_thread_.SetPriority(rtc::kRealtimePriority);
insert_packet_thread_.Start();
insert_packet_thread_.SetPriority(rtc::kRealtimePriority);
pull_audio_thread_.Start();
pull_audio_thread_.SetPriority(rtc::kRealtimePriority);
}
void TearDown() {
AudioCodingModuleTestOldApi::TearDown();
pull_audio_thread_->Stop();
send_thread_->Stop();
insert_packet_thread_->Stop();
pull_audio_thread_.Stop();
send_thread_.Stop();
insert_packet_thread_.Stop();
}
EventTypeWrapper RunTest() {
@ -573,9 +569,9 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
return true;
}
rtc::scoped_ptr<PlatformThread> send_thread_;
rtc::scoped_ptr<PlatformThread> insert_packet_thread_;
rtc::scoped_ptr<PlatformThread> pull_audio_thread_;
rtc::PlatformThread send_thread_;
rtc::PlatformThread insert_packet_thread_;
rtc::PlatformThread pull_audio_thread_;
const rtc::scoped_ptr<EventWrapper> test_complete_;
int send_count_;
int insert_packet_count_;
@ -702,12 +698,10 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
AcmReRegisterIsacMtTestOldApi()
: AudioCodingModuleTestOldApi(),
receive_thread_(
PlatformThread::CreateThread(CbReceiveThread, this, "receive")),
codec_registration_thread_(
PlatformThread::CreateThread(CbCodecRegistrationThread,
this,
"codec_registration")),
receive_thread_(CbReceiveThread, this, "receive"),
codec_registration_thread_(CbCodecRegistrationThread,
this,
"codec_registration"),
test_complete_(EventWrapper::Create()),
crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
codec_registered_(false),
@ -743,16 +737,16 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
}
void StartThreads() {
ASSERT_TRUE(receive_thread_->Start());
receive_thread_->SetPriority(kRealtimePriority);
ASSERT_TRUE(codec_registration_thread_->Start());
codec_registration_thread_->SetPriority(kRealtimePriority);
receive_thread_.Start();
receive_thread_.SetPriority(rtc::kRealtimePriority);
codec_registration_thread_.Start();
codec_registration_thread_.SetPriority(rtc::kRealtimePriority);
}
void TearDown() {
AudioCodingModuleTestOldApi::TearDown();
receive_thread_->Stop();
codec_registration_thread_->Stop();
receive_thread_.Stop();
codec_registration_thread_.Stop();
}
EventTypeWrapper RunTest() {
@ -831,8 +825,8 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
return true;
}
rtc::scoped_ptr<PlatformThread> receive_thread_;
rtc::scoped_ptr<PlatformThread> codec_registration_thread_;
rtc::PlatformThread receive_thread_;
rtc::PlatformThread codec_registration_thread_;
const rtc::scoped_ptr<EventWrapper> test_complete_;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
bool codec_registered_ GUARDED_BY(crit_sect_);

View File

@ -36,12 +36,6 @@ namespace webrtc {
#define TEST_DURATION_SEC 600
#define NUMBER_OF_SENDER_TESTS 6
#define MAX_FILE_NAME_LENGTH_BYTE 500
#define CHECK_THREAD_NULLITY(myThread, S) \
if(myThread != NULL) { \
(myThread)->Start(); \
} else { \
ADD_FAILURE() << S; \
}
void APITest::Wait(uint32_t waitLengthMs) {
if (_randomTest) {
@ -522,38 +516,34 @@ void APITest::Perform() {
//--- THREADS
// A
// PUSH
rtc::scoped_ptr<PlatformThread> myPushAudioThreadA =
PlatformThread::CreateThread(PushAudioThreadA, this, "PushAudioThreadA");
CHECK_THREAD_NULLITY(myPushAudioThreadA, "Unable to start A::PUSH thread");
rtc::PlatformThread myPushAudioThreadA(PushAudioThreadA, this,
"PushAudioThreadA");
myPushAudioThreadA.Start();
// PULL
rtc::scoped_ptr<PlatformThread> myPullAudioThreadA =
PlatformThread::CreateThread(PullAudioThreadA, this, "PullAudioThreadA");
CHECK_THREAD_NULLITY(myPullAudioThreadA, "Unable to start A::PULL thread");
rtc::PlatformThread myPullAudioThreadA(PullAudioThreadA, this,
"PullAudioThreadA");
myPullAudioThreadA.Start();
// Process
rtc::scoped_ptr<PlatformThread> myProcessThreadA =
PlatformThread::CreateThread(ProcessThreadA, this, "ProcessThreadA");
CHECK_THREAD_NULLITY(myProcessThreadA, "Unable to start A::Process thread");
rtc::PlatformThread myProcessThreadA(ProcessThreadA, this, "ProcessThreadA");
myProcessThreadA.Start();
// API
rtc::scoped_ptr<PlatformThread> myAPIThreadA =
PlatformThread::CreateThread(APIThreadA, this, "APIThreadA");
CHECK_THREAD_NULLITY(myAPIThreadA, "Unable to start A::API thread");
rtc::PlatformThread myAPIThreadA(APIThreadA, this, "APIThreadA");
myAPIThreadA.Start();
// B
// PUSH
rtc::scoped_ptr<PlatformThread> myPushAudioThreadB =
PlatformThread::CreateThread(PushAudioThreadB, this, "PushAudioThreadB");
CHECK_THREAD_NULLITY(myPushAudioThreadB, "Unable to start B::PUSH thread");
rtc::PlatformThread myPushAudioThreadB(PushAudioThreadB, this,
"PushAudioThreadB");
myPushAudioThreadB.Start();
// PULL
rtc::scoped_ptr<PlatformThread> myPullAudioThreadB =
PlatformThread::CreateThread(PullAudioThreadB, this, "PullAudioThreadB");
CHECK_THREAD_NULLITY(myPullAudioThreadB, "Unable to start B::PULL thread");
rtc::PlatformThread myPullAudioThreadB(PullAudioThreadB, this,
"PullAudioThreadB");
myPullAudioThreadB.Start();
// Process
rtc::scoped_ptr<PlatformThread> myProcessThreadB =
PlatformThread::CreateThread(ProcessThreadB, this, "ProcessThreadB");
CHECK_THREAD_NULLITY(myProcessThreadB, "Unable to start B::Process thread");
rtc::PlatformThread myProcessThreadB(ProcessThreadB, this, "ProcessThreadB");
myProcessThreadB.Start();
// API
rtc::scoped_ptr<PlatformThread> myAPIThreadB =
PlatformThread::CreateThread(APIThreadB, this, "APIThreadB");
CHECK_THREAD_NULLITY(myAPIThreadB, "Unable to start B::API thread");
rtc::PlatformThread myAPIThreadB(APIThreadB, this, "APIThreadB");
myAPIThreadB.Start();
//_apiEventA->StartTimer(true, 5000);
//_apiEventB->StartTimer(true, 5000);
@ -587,15 +577,15 @@ void APITest::Perform() {
//(unsigned long)((unsigned long)TEST_DURATION_SEC * (unsigned long)1000));
delete completeEvent;
myPushAudioThreadA->Stop();
myPullAudioThreadA->Stop();
myProcessThreadA->Stop();
myAPIThreadA->Stop();
myPushAudioThreadA.Stop();
myPullAudioThreadA.Stop();
myProcessThreadA.Stop();
myAPIThreadA.Stop();
myPushAudioThreadB->Stop();
myPullAudioThreadB->Stop();
myProcessThreadB->Stop();
myAPIThreadB->Stop();
myPushAudioThreadB.Stop();
myPullAudioThreadB.Stop();
myProcessThreadB.Stop();
myAPIThreadB.Stop();
}
void APITest::CheckVADStatus(char side) {