Index: webrtc/system_wrappers/source/condition_variable_unittest.cc |
diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc |
index 2e873dca1687e924d653d79d401da67ecf1ea966..4b1b6cc608998d8721323e1e19bb929e3b9c3c5c 100644 |
--- a/webrtc/system_wrappers/source/condition_variable_unittest.cc |
+++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc |
@@ -8,13 +8,13 @@ |
* be found in the AUTHORS file in the root of the source tree. |
*/ |
-#include "webrtc/system_wrappers/include/condition_variable_wrapper.h" |
- |
// TODO(tommi): Remove completely. As is there is still some code for Windows |
-// that relies on ConditionVariableWrapper, but code has been removed on other |
+// that relies on ConditionVariableEventWin, but code has been removed on other |
// platforms. |
#if defined(WEBRTC_WIN) |
+#include "webrtc/system_wrappers/source/condition_variable_event_win.h" |
+ |
#include "testing/gtest/include/gtest/gtest.h" |
#include "webrtc/base/platform_thread.h" |
#include "webrtc/base/scoped_ptr.h" |
@@ -40,37 +40,36 @@ const int kVeryShortWaitMs = 20; // Used when we want a timeout |
class Baton { |
public: |
Baton() |
- : giver_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
- crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
- cond_var_(ConditionVariableWrapper::CreateConditionVariable()), |
- being_passed_(false), |
+ : being_passed_(false), |
pass_count_(0) { |
+ InitializeCriticalSection(&crit_sect_); |
} |
~Baton() { |
- delete giver_sect_; |
- delete crit_sect_; |
- delete cond_var_; |
+ DeleteCriticalSection(&crit_sect_); |
} |
// Pass the baton. Returns false if baton is not picked up in |max_msecs|. |
// Only one process can pass at the same time; this property is |
// ensured by the |giver_sect_| lock. |
bool Pass(uint32_t max_msecs) { |
- CriticalSectionScoped cs_giver(giver_sect_); |
- CriticalSectionScoped cs(crit_sect_); |
+ CriticalSectionScoped cs_giver(&giver_sect_); |
+ EnterCriticalSection(&crit_sect_); |
SignalBatonAvailable(); |
const bool result = TakeBatonIfStillFree(max_msecs); |
if (result) { |
++pass_count_; |
} |
+ LeaveCriticalSection(&crit_sect_); |
return result; |
} |
// Grab the baton. Returns false if baton is not passed. |
bool Grab(uint32_t max_msecs) { |
- CriticalSectionScoped cs(crit_sect_); |
- return WaitUntilBatonOffered(max_msecs); |
+ EnterCriticalSection(&crit_sect_); |
+ bool ret = WaitUntilBatonOffered(max_msecs); |
+ LeaveCriticalSection(&crit_sect_); |
+ return ret; |
} |
int PassCount() { |
@@ -79,7 +78,7 @@ class Baton { |
// finishes. I.e. the Grab()-call may finish before |pass_count_| has been |
// incremented. |
// Thus, this function waits on giver_sect_. |
- CriticalSectionScoped cs(giver_sect_); |
+ CriticalSectionScoped cs(&giver_sect_); |
return pass_count_; |
} |
@@ -88,19 +87,19 @@ class Baton { |
// These functions must be called with crit_sect_ held. |
bool WaitUntilBatonOffered(int timeout_ms) { |
while (!being_passed_) { |
- if (!cond_var_->SleepCS(*crit_sect_, timeout_ms)) { |
+ if (!cond_var_.SleepCS(&crit_sect_, timeout_ms)) { |
return false; |
} |
} |
being_passed_ = false; |
- cond_var_->Wake(); |
+ cond_var_.Wake(); |
return true; |
} |
void SignalBatonAvailable() { |
assert(!being_passed_); |
being_passed_ = true; |
- cond_var_->Wake(); |
+ cond_var_.Wake(); |
} |
// Timeout extension: Wait for a limited time for someone else to |
@@ -112,27 +111,25 @@ class Baton { |
bool TakeBatonIfStillFree(int timeout_ms) { |
bool not_timeout = true; |
while (being_passed_ && not_timeout) { |
- not_timeout = cond_var_->SleepCS(*crit_sect_, timeout_ms); |
+ not_timeout = cond_var_.SleepCS(&crit_sect_, timeout_ms); |
// If we're woken up while variable is still held, we may have |
// gotten a wakeup destined for a grabber thread. |
// This situation is not treated specially here. |
} |
- if (!being_passed_) { |
+ if (!being_passed_) |
return true; |
- } else { |
- assert(!not_timeout); |
- being_passed_ = false; |
- return false; |
- } |
+ assert(!not_timeout); |
+ being_passed_ = false; |
+ return false; |
} |
// Lock that ensures that there is only one thread in the active |
// part of Pass() at a time. |
// |giver_sect_| must always be acquired before |cond_var_|. |
- CriticalSectionWrapper* giver_sect_; |
+ CriticalSectionWrapper giver_sect_; |
// Lock that protects |being_passed_|. |
- CriticalSectionWrapper* crit_sect_; |
- ConditionVariableWrapper* cond_var_; |
+ CRITICAL_SECTION crit_sect_; |
+ ConditionVariableEventWin cond_var_; |
bool being_passed_; |
// Statistics information: Number of successfull passes. |
int pass_count_; |
@@ -191,16 +188,17 @@ TEST_F(CondVarTest, DISABLED_PassBatonMultipleTimes) { |
} |
TEST(CondVarWaitTest, WaitingWaits) { |
- rtc::scoped_ptr<CriticalSectionWrapper> crit_sect( |
- CriticalSectionWrapper::CreateCriticalSection()); |
- rtc::scoped_ptr<ConditionVariableWrapper> cond_var( |
- ConditionVariableWrapper::CreateConditionVariable()); |
- CriticalSectionScoped cs(crit_sect.get()); |
+ CRITICAL_SECTION crit_sect; |
+ InitializeCriticalSection(&crit_sect); |
+ ConditionVariableEventWin cond_var; |
+ EnterCriticalSection(&crit_sect); |
int64_t start_ms = TickTime::MillisecondTimestamp(); |
- EXPECT_FALSE(cond_var->SleepCS(*(crit_sect), kVeryShortWaitMs)); |
+ EXPECT_FALSE(cond_var.SleepCS(&crit_sect, kVeryShortWaitMs)); |
int64_t end_ms = TickTime::MillisecondTimestamp(); |
EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms) |
<< "actual elapsed:" << end_ms - start_ms; |
+ LeaveCriticalSection(&crit_sect); |
+ DeleteCriticalSection(&crit_sect); |
} |
} // anonymous namespace |