Made CPU initialization on Windows lazy to prevent long startup time.

Review URL: http://webrtc-codereview.appspot.com/268014

git-svn-id: http://webrtc.googlecode.com/svn/trunk@977 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2011-11-18 16:25:54 +00:00
parent 543611a77a
commit 3798ecb25b
2 changed files with 13 additions and 15 deletions

View File

@ -67,8 +67,7 @@ CpuWindows::CpuWindows()
// All resources are allocated in PollingCpu().
if (AllocateComplexDataTypes())
{
const bool success = StartPollingCpu();
assert(success);
StartPollingCpu();
}
else
{
@ -135,30 +134,29 @@ void CpuWindows::DeAllocateComplexDataTypes()
}
}
bool CpuWindows::StartPollingCpu()
void CpuWindows::StartPollingCpu()
{
unsigned int dummy_id = 0;
if (!cpu_polling_thread->Start(dummy_id))
{
return false;
initialize_ = false;
assert(false);
}
}
bool CpuWindows::StopPollingCpu()
{
{
// If StopPollingCpu is called immediately after StartPollingCpu() it is
// possible that cpu_polling_thread is in the process of initializing.
// Let initialization finish to avoid getting into a bad state.
CriticalSectionScoped cs(*init_crit_);
while(initialize_)
{
init_cond_->SleepCS(*init_crit_);
}
}
if (!has_initialized_)
{
cpu_polling_thread->Stop();
return false;
}
return has_initialized_;
}
bool CpuWindows::StopPollingCpu()
{
if (!has_initialized_)
{
return false;
@ -204,7 +202,7 @@ bool CpuWindows::ProcessImpl()
{
has_initialized_ = false;
terminate_ = true;
return false;
return true;
}
}
// Approximately one seconds sleep for each CPU measurement. Precision is

View File

@ -45,7 +45,7 @@ private:
bool AllocateComplexDataTypes();
void DeAllocateComplexDataTypes();
bool StartPollingCpu();
void StartPollingCpu();
bool StopPollingCpu();
static bool Process(void* thread_object);