Reformatted critical_section wrappers.
BUG= TEST=ran trybots Review URL: https://webrtc-codereview.appspot.com/971012 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3210 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// For Sleep()
|
||||
#include <windows.h>
|
||||
@ -16,13 +18,11 @@
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include "system_wrappers/interface/critical_section_wrapper.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "system_wrappers/interface/sleep.h"
|
||||
#include "system_wrappers/interface/thread_wrapper.h"
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
#include "system_wrappers/source/unittest_utilities.h"
|
||||
#include "webrtc/system_wrappers/interface/sleep.h"
|
||||
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
|
||||
#include "webrtc/system_wrappers/interface/trace.h"
|
||||
#include "webrtc/system_wrappers/source/unittest_utilities.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -39,7 +39,7 @@ static void SwitchProcess() {
|
||||
}
|
||||
|
||||
class ProtectedCount {
|
||||
public:
|
||||
public:
|
||||
explicit ProtectedCount(CriticalSectionWrapper* crit_sect)
|
||||
: crit_sect_(crit_sect),
|
||||
count_(0) {
|
||||
@ -55,13 +55,13 @@ class ProtectedCount {
|
||||
return count_;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
CriticalSectionWrapper* crit_sect_;
|
||||
int count_;
|
||||
};
|
||||
|
||||
class CritSectTest : public ::testing::Test {
|
||||
public:
|
||||
public:
|
||||
CritSectTest() : trace_(kLogTrace) {
|
||||
}
|
||||
|
||||
@ -72,26 +72,26 @@ class CritSectTest : public ::testing::Test {
|
||||
// On Posix, this SwitchProcess() needs to be in a loop to make the
|
||||
// test both fast and non-flaky.
|
||||
// With 1 us wait as the switch, up to 7 rounds have been observed.
|
||||
while (count->Count() < target && loop_counter < 100*target) {
|
||||
while (count->Count() < target && loop_counter < 100 * target) {
|
||||
++loop_counter;
|
||||
SwitchProcess();
|
||||
}
|
||||
return (count->Count() >= target);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
ScopedTracing trace_;
|
||||
};
|
||||
|
||||
bool LockUnlockThenStopRunFunction(void* obj) {
|
||||
ProtectedCount* the_count = static_cast<ProtectedCount*> (obj);
|
||||
ProtectedCount* the_count = static_cast<ProtectedCount*>(obj);
|
||||
the_count->Increment();
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_F(CritSectTest, ThreadWakesOnce) {
|
||||
CriticalSectionWrapper* crit_sect
|
||||
= CriticalSectionWrapper::CreateCriticalSection();
|
||||
CriticalSectionWrapper* crit_sect =
|
||||
CriticalSectionWrapper::CreateCriticalSection();
|
||||
ProtectedCount count(crit_sect);
|
||||
ThreadWrapper* thread = ThreadWrapper::CreateThread(
|
||||
&LockUnlockThenStopRunFunction, &count);
|
||||
@ -112,15 +112,15 @@ TEST_F(CritSectTest, ThreadWakesOnce) {
|
||||
}
|
||||
|
||||
bool LockUnlockRunFunction(void* obj) {
|
||||
ProtectedCount* the_count = static_cast<ProtectedCount*> (obj);
|
||||
ProtectedCount* the_count = static_cast<ProtectedCount*>(obj);
|
||||
the_count->Increment();
|
||||
SwitchProcess();
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_F(CritSectTest, ThreadWakesTwice) {
|
||||
CriticalSectionWrapper* crit_sect
|
||||
= CriticalSectionWrapper::CreateCriticalSection();
|
||||
CriticalSectionWrapper* crit_sect =
|
||||
CriticalSectionWrapper::CreateCriticalSection();
|
||||
ProtectedCount count(crit_sect);
|
||||
ThreadWrapper* thread = ThreadWrapper::CreateThread(&LockUnlockRunFunction,
|
||||
&count);
|
||||
|
||||
Reference in New Issue
Block a user