OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/synchronization/read_write_lock.h" | 5 #include "base/synchronization/read_write_lock.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); | 102 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
103 PlatformThread::Join(handle); | 103 PlatformThread::Join(handle); |
104 EXPECT_TRUE(thread.did_acquire()); | 104 EXPECT_TRUE(thread.did_acquire()); |
105 } | 105 } |
106 | 106 |
107 // Tests that writer locks exclude reader locks. | 107 // Tests that writer locks exclude reader locks. |
108 | 108 |
109 class ReadAndWriteReadWriteLockTestThread : public PlatformThread::Delegate { | 109 class ReadAndWriteReadWriteLockTestThread : public PlatformThread::Delegate { |
110 public: | 110 public: |
111 ReadAndWriteReadWriteLockTestThread(ReadWriteLock* lock, int* value) | 111 ReadAndWriteReadWriteLockTestThread(ReadWriteLock* lock, int* value) |
112 : lock_(lock), value_(value), | 112 : lock_(lock), |
113 event_(true /* manual_reset */, false /* initially_signaled */) {} | 113 value_(value), |
| 114 event_(WaitableEvent::ResetPolicy::MANUAL, |
| 115 WaitableEvent::InitialState::NOT_SIGNALED) {} |
114 | 116 |
115 void ThreadMain() override { | 117 void ThreadMain() override { |
116 AutoWriteLock locker(*lock_); | 118 AutoWriteLock locker(*lock_); |
117 (*value_)++; | 119 (*value_)++; |
118 event_.Signal(); | 120 event_.Signal(); |
119 } | 121 } |
120 | 122 |
121 void Wait() { | 123 void Wait() { |
122 event_.Wait(); | 124 event_.Wait(); |
123 } | 125 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 216 |
215 PlatformThread::Join(handle1); | 217 PlatformThread::Join(handle1); |
216 PlatformThread::Join(handle2); | 218 PlatformThread::Join(handle2); |
217 PlatformThread::Join(handle3); | 219 PlatformThread::Join(handle3); |
218 | 220 |
219 EXPECT_EQ(4 * 40, value); | 221 EXPECT_EQ(4 * 40, value); |
220 } | 222 } |
221 | 223 |
222 } // namespace subtle | 224 } // namespace subtle |
223 } // namespace base | 225 } // namespace base |
OLD | NEW |