Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1872)

Unified Diff: base/synchronization/waitable_event_unittest.cc

Issue 419773002: Take extra lock in base::WaitableEvent::WaitMany. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/waitable_event_unittest.cc
diff --git a/base/synchronization/waitable_event_unittest.cc b/base/synchronization/waitable_event_unittest.cc
index b66f6e8720050d4d4912c0f4ac5a55e7eb77f4a3..0b50d817102f68ce830bf4cfa247a683d9413dff 100644
--- a/base/synchronization/waitable_event_unittest.cc
+++ b/base/synchronization/waitable_event_unittest.cc
@@ -79,7 +79,7 @@ class WaitableEventSignaler : public PlatformThread::Delegate {
}
virtual void ThreadMain() OVERRIDE {
- PlatformThread::Sleep(TimeDelta::FromSeconds(static_cast<int>(seconds_)));
+ PlatformThread::Sleep(TimeDelta::FromSecondsD(seconds_));
ev_->Signal();
}
@@ -88,21 +88,43 @@ class WaitableEventSignaler : public PlatformThread::Delegate {
WaitableEvent *const ev_;
};
+TEST(WaitableEventTest, WaitAndDelete) {
+ // This test tests that if a WaitableEvent can be safely deleted
+ // when |Wait| is done without additional synchrnization.
+ // If this test crashes, it is a bug.
+
+ WaitableEvent* ev = new WaitableEvent(false, false);
+
+ WaitableEventSignaler signaler(0.01, ev);
+ PlatformThreadHandle thread;
+ PlatformThread::Create(0, &signaler, &thread);
+
+ ev->Wait();
+ delete ev;
+
+ PlatformThread::Join(thread);
+}
+
TEST(WaitableEventTest, WaitMany) {
+ // This test tests that if a WaitableEvent can be safely deleted
+ // when |WaitMany| is done without additional synchrnization.
+ // If this test crashes, it is a bug.
+
WaitableEvent* ev[5];
for (unsigned i = 0; i < 5; ++i)
ev[i] = new WaitableEvent(false, false);
- WaitableEventSignaler signaler(0.1, ev[2]);
+ WaitableEventSignaler signaler(0.01, ev[2]);
PlatformThreadHandle thread;
PlatformThread::Create(0, &signaler, &thread);
- EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 2u);
-
- PlatformThread::Join(thread);
+ size_t index = WaitableEvent::WaitMany(ev, 5);
for (unsigned i = 0; i < 5; ++i)
delete ev[i];
+
+ PlatformThread::Join(thread);
+ EXPECT_EQ(2u, index);
}
} // namespace base
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698