OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a | 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a |
6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to | 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to |
7 // increase tolerance and reduce observed flakiness (though doing so reduces the | 7 // increase tolerance and reduce observed flakiness (though doing so reduces the |
8 // meaningfulness of the test). | 8 // meaningfulness of the test). |
9 | 9 |
10 #include "mojo/edk/system/waiter_list.h" | 10 #include "mojo/edk/system/awakable_list.h" |
11 | 11 |
12 #include "base/threading/platform_thread.h" // For |Sleep()|. | 12 #include "base/threading/platform_thread.h" // For |Sleep()|. |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "mojo/edk/system/handle_signals_state.h" | 14 #include "mojo/edk/system/handle_signals_state.h" |
15 #include "mojo/edk/system/test_utils.h" | 15 #include "mojo/edk/system/test_utils.h" |
16 #include "mojo/edk/system/waiter.h" | 16 #include "mojo/edk/system/waiter.h" |
17 #include "mojo/edk/system/waiter_test_utils.h" | 17 #include "mojo/edk/system/waiter_test_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 namespace system { | 21 namespace system { |
22 namespace { | 22 namespace { |
23 | 23 |
24 TEST(WaiterListTest, BasicCancel) { | 24 TEST(AwakableListTest, BasicCancel) { |
25 MojoResult result; | 25 MojoResult result; |
26 uint32_t context; | 26 uint32_t context; |
27 | 27 |
28 // Cancel immediately after thread start. | 28 // Cancel immediately after thread start. |
29 { | 29 { |
30 WaiterList waiter_list; | 30 AwakableList awakable_list; |
31 test::SimpleWaiterThread thread(&result, &context); | 31 test::SimpleWaiterThread thread(&result, &context); |
32 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); | 32 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
33 thread.Start(); | 33 thread.Start(); |
34 waiter_list.CancelAllWaiters(); | 34 awakable_list.CancelAll(); |
35 // Double-remove okay: | 35 // Double-remove okay: |
36 waiter_list.RemoveWaiter(thread.waiter()); | 36 awakable_list.Remove(thread.waiter()); |
37 } // Join |thread|. | 37 } // Join |thread|. |
38 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 38 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
39 EXPECT_EQ(1u, context); | 39 EXPECT_EQ(1u, context); |
40 | 40 |
41 // Cancel before after thread start. | 41 // Cancel before after thread start. |
42 { | 42 { |
43 WaiterList waiter_list; | 43 AwakableList awakable_list; |
44 test::SimpleWaiterThread thread(&result, &context); | 44 test::SimpleWaiterThread thread(&result, &context); |
45 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); | 45 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); |
46 waiter_list.CancelAllWaiters(); | 46 awakable_list.CancelAll(); |
47 thread.Start(); | 47 thread.Start(); |
48 } // Join |thread|. | 48 } // Join |thread|. |
49 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 49 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
50 EXPECT_EQ(2u, context); | 50 EXPECT_EQ(2u, context); |
51 | 51 |
52 // Cancel some time after thread start. | 52 // Cancel some time after thread start. |
53 { | 53 { |
54 WaiterList waiter_list; | 54 AwakableList awakable_list; |
55 test::SimpleWaiterThread thread(&result, &context); | 55 test::SimpleWaiterThread thread(&result, &context); |
56 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); | 56 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); |
57 thread.Start(); | 57 thread.Start(); |
58 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 58 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
59 waiter_list.CancelAllWaiters(); | 59 awakable_list.CancelAll(); |
60 } // Join |thread|. | 60 } // Join |thread|. |
61 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 61 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
62 EXPECT_EQ(3u, context); | 62 EXPECT_EQ(3u, context); |
63 } | 63 } |
64 | 64 |
65 TEST(WaiterListTest, BasicAwakeSatisfied) { | 65 TEST(AwakableListTest, BasicAwakeSatisfied) { |
66 MojoResult result; | 66 MojoResult result; |
67 uint32_t context; | 67 uint32_t context; |
68 | 68 |
69 // Awake immediately after thread start. | 69 // Awake immediately after thread start. |
70 { | 70 { |
71 WaiterList waiter_list; | 71 AwakableList awakable_list; |
72 test::SimpleWaiterThread thread(&result, &context); | 72 test::SimpleWaiterThread thread(&result, &context); |
73 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); | 73 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
74 thread.Start(); | 74 thread.Start(); |
75 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 75 awakable_list.AwakeForStateChange(HandleSignalsState( |
76 MOJO_HANDLE_SIGNAL_READABLE, | 76 MOJO_HANDLE_SIGNAL_READABLE, |
77 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 77 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
78 waiter_list.RemoveWaiter(thread.waiter()); | 78 awakable_list.Remove(thread.waiter()); |
79 } // Join |thread|. | 79 } // Join |thread|. |
80 EXPECT_EQ(MOJO_RESULT_OK, result); | 80 EXPECT_EQ(MOJO_RESULT_OK, result); |
81 EXPECT_EQ(1u, context); | 81 EXPECT_EQ(1u, context); |
82 | 82 |
83 // Awake before after thread start. | 83 // Awake before after thread start. |
84 { | 84 { |
85 WaiterList waiter_list; | 85 AwakableList awakable_list; |
86 test::SimpleWaiterThread thread(&result, &context); | 86 test::SimpleWaiterThread thread(&result, &context); |
87 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); | 87 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); |
88 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 88 awakable_list.AwakeForStateChange(HandleSignalsState( |
89 MOJO_HANDLE_SIGNAL_WRITABLE, | 89 MOJO_HANDLE_SIGNAL_WRITABLE, |
90 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 90 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
91 waiter_list.RemoveWaiter(thread.waiter()); | 91 awakable_list.Remove(thread.waiter()); |
92 // Double-remove okay: | 92 // Double-remove okay: |
93 waiter_list.RemoveWaiter(thread.waiter()); | 93 awakable_list.Remove(thread.waiter()); |
94 thread.Start(); | 94 thread.Start(); |
95 } // Join |thread|. | 95 } // Join |thread|. |
96 EXPECT_EQ(MOJO_RESULT_OK, result); | 96 EXPECT_EQ(MOJO_RESULT_OK, result); |
97 EXPECT_EQ(2u, context); | 97 EXPECT_EQ(2u, context); |
98 | 98 |
99 // Awake some time after thread start. | 99 // Awake some time after thread start. |
100 { | 100 { |
101 WaiterList waiter_list; | 101 AwakableList awakable_list; |
102 test::SimpleWaiterThread thread(&result, &context); | 102 test::SimpleWaiterThread thread(&result, &context); |
103 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); | 103 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); |
104 thread.Start(); | 104 thread.Start(); |
105 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 105 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
106 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 106 awakable_list.AwakeForStateChange(HandleSignalsState( |
107 MOJO_HANDLE_SIGNAL_READABLE, | 107 MOJO_HANDLE_SIGNAL_READABLE, |
108 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 108 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
109 waiter_list.RemoveWaiter(thread.waiter()); | 109 awakable_list.Remove(thread.waiter()); |
110 } // Join |thread|. | 110 } // Join |thread|. |
111 EXPECT_EQ(MOJO_RESULT_OK, result); | 111 EXPECT_EQ(MOJO_RESULT_OK, result); |
112 EXPECT_EQ(3u, context); | 112 EXPECT_EQ(3u, context); |
113 } | 113 } |
114 | 114 |
115 TEST(WaiterListTest, BasicAwakeUnsatisfiable) { | 115 TEST(AwakableListTest, BasicAwakeUnsatisfiable) { |
116 MojoResult result; | 116 MojoResult result; |
117 uint32_t context; | 117 uint32_t context; |
118 | 118 |
119 // Awake (for unsatisfiability) immediately after thread start. | 119 // Awake (for unsatisfiability) immediately after thread start. |
120 { | 120 { |
121 WaiterList waiter_list; | 121 AwakableList awakable_list; |
122 test::SimpleWaiterThread thread(&result, &context); | 122 test::SimpleWaiterThread thread(&result, &context); |
123 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); | 123 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
124 thread.Start(); | 124 thread.Start(); |
125 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 125 awakable_list.AwakeForStateChange(HandleSignalsState( |
126 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); | 126 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); |
127 waiter_list.RemoveWaiter(thread.waiter()); | 127 awakable_list.Remove(thread.waiter()); |
128 } // Join |thread|. | 128 } // Join |thread|. |
129 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 129 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
130 EXPECT_EQ(1u, context); | 130 EXPECT_EQ(1u, context); |
131 | 131 |
132 // Awake (for unsatisfiability) before after thread start. | 132 // Awake (for unsatisfiability) before after thread start. |
133 { | 133 { |
134 WaiterList waiter_list; | 134 AwakableList awakable_list; |
135 test::SimpleWaiterThread thread(&result, &context); | 135 test::SimpleWaiterThread thread(&result, &context); |
136 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); | 136 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); |
137 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 137 awakable_list.AwakeForStateChange(HandleSignalsState( |
138 MOJO_HANDLE_SIGNAL_READABLE, MOJO_HANDLE_SIGNAL_READABLE)); | 138 MOJO_HANDLE_SIGNAL_READABLE, MOJO_HANDLE_SIGNAL_READABLE)); |
139 waiter_list.RemoveWaiter(thread.waiter()); | 139 awakable_list.Remove(thread.waiter()); |
140 thread.Start(); | 140 thread.Start(); |
141 } // Join |thread|. | 141 } // Join |thread|. |
142 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 142 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
143 EXPECT_EQ(2u, context); | 143 EXPECT_EQ(2u, context); |
144 | 144 |
145 // Awake (for unsatisfiability) some time after thread start. | 145 // Awake (for unsatisfiability) some time after thread start. |
146 { | 146 { |
147 WaiterList waiter_list; | 147 AwakableList awakable_list; |
148 test::SimpleWaiterThread thread(&result, &context); | 148 test::SimpleWaiterThread thread(&result, &context); |
149 waiter_list.AddWaiter(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); | 149 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); |
150 thread.Start(); | 150 thread.Start(); |
151 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 151 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
152 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 152 awakable_list.AwakeForStateChange(HandleSignalsState( |
153 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); | 153 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); |
154 waiter_list.RemoveWaiter(thread.waiter()); | 154 awakable_list.Remove(thread.waiter()); |
155 // Double-remove okay: | 155 // Double-remove okay: |
156 waiter_list.RemoveWaiter(thread.waiter()); | 156 awakable_list.Remove(thread.waiter()); |
157 } // Join |thread|. | 157 } // Join |thread|. |
158 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 158 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
159 EXPECT_EQ(3u, context); | 159 EXPECT_EQ(3u, context); |
160 } | 160 } |
161 | 161 |
162 TEST(WaiterListTest, MultipleWaiters) { | 162 TEST(AwakableListTest, MultipleAwakables) { |
163 MojoResult result1; | 163 MojoResult result1; |
164 MojoResult result2; | 164 MojoResult result2; |
165 MojoResult result3; | 165 MojoResult result3; |
166 MojoResult result4; | 166 MojoResult result4; |
167 uint32_t context1; | 167 uint32_t context1; |
168 uint32_t context2; | 168 uint32_t context2; |
169 uint32_t context3; | 169 uint32_t context3; |
170 uint32_t context4; | 170 uint32_t context4; |
171 | 171 |
172 // Cancel two waiters. | 172 // Cancel two awakables. |
173 { | 173 { |
174 WaiterList waiter_list; | 174 AwakableList awakable_list; |
175 test::SimpleWaiterThread thread1(&result1, &context1); | 175 test::SimpleWaiterThread thread1(&result1, &context1); |
176 waiter_list.AddWaiter(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); | 176 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
177 thread1.Start(); | 177 thread1.Start(); |
178 test::SimpleWaiterThread thread2(&result2, &context2); | 178 test::SimpleWaiterThread thread2(&result2, &context2); |
179 waiter_list.AddWaiter(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); | 179 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); |
180 thread2.Start(); | 180 thread2.Start(); |
181 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 181 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
182 waiter_list.CancelAllWaiters(); | 182 awakable_list.CancelAll(); |
183 } // Join threads. | 183 } // Join threads. |
184 EXPECT_EQ(MOJO_RESULT_CANCELLED, result1); | 184 EXPECT_EQ(MOJO_RESULT_CANCELLED, result1); |
185 EXPECT_EQ(1u, context1); | 185 EXPECT_EQ(1u, context1); |
186 EXPECT_EQ(MOJO_RESULT_CANCELLED, result2); | 186 EXPECT_EQ(MOJO_RESULT_CANCELLED, result2); |
187 EXPECT_EQ(2u, context2); | 187 EXPECT_EQ(2u, context2); |
188 | 188 |
189 // Awake one waiter, cancel other. | 189 // Awake one awakable, cancel other. |
190 { | 190 { |
191 WaiterList waiter_list; | 191 AwakableList awakable_list; |
192 test::SimpleWaiterThread thread1(&result1, &context1); | 192 test::SimpleWaiterThread thread1(&result1, &context1); |
193 waiter_list.AddWaiter(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); | 193 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); |
194 thread1.Start(); | 194 thread1.Start(); |
195 test::SimpleWaiterThread thread2(&result2, &context2); | 195 test::SimpleWaiterThread thread2(&result2, &context2); |
196 waiter_list.AddWaiter(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 4); | 196 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 4); |
197 thread2.Start(); | 197 thread2.Start(); |
198 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 198 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
199 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 199 awakable_list.AwakeForStateChange(HandleSignalsState( |
200 MOJO_HANDLE_SIGNAL_READABLE, | 200 MOJO_HANDLE_SIGNAL_READABLE, |
201 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 201 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
202 waiter_list.RemoveWaiter(thread1.waiter()); | 202 awakable_list.Remove(thread1.waiter()); |
203 waiter_list.CancelAllWaiters(); | 203 awakable_list.CancelAll(); |
204 } // Join threads. | 204 } // Join threads. |
205 EXPECT_EQ(MOJO_RESULT_OK, result1); | 205 EXPECT_EQ(MOJO_RESULT_OK, result1); |
206 EXPECT_EQ(3u, context1); | 206 EXPECT_EQ(3u, context1); |
207 EXPECT_EQ(MOJO_RESULT_CANCELLED, result2); | 207 EXPECT_EQ(MOJO_RESULT_CANCELLED, result2); |
208 EXPECT_EQ(4u, context2); | 208 EXPECT_EQ(4u, context2); |
209 | 209 |
210 // Cancel one waiter, awake other for unsatisfiability. | 210 // Cancel one awakable, awake other for unsatisfiability. |
211 { | 211 { |
212 WaiterList waiter_list; | 212 AwakableList awakable_list; |
213 test::SimpleWaiterThread thread1(&result1, &context1); | 213 test::SimpleWaiterThread thread1(&result1, &context1); |
214 waiter_list.AddWaiter(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 5); | 214 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 5); |
215 thread1.Start(); | 215 thread1.Start(); |
216 test::SimpleWaiterThread thread2(&result2, &context2); | 216 test::SimpleWaiterThread thread2(&result2, &context2); |
217 waiter_list.AddWaiter(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 6); | 217 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 6); |
218 thread2.Start(); | 218 thread2.Start(); |
219 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 219 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
220 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 220 awakable_list.AwakeForStateChange(HandleSignalsState( |
221 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_READABLE)); | 221 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_READABLE)); |
222 waiter_list.RemoveWaiter(thread2.waiter()); | 222 awakable_list.Remove(thread2.waiter()); |
223 waiter_list.CancelAllWaiters(); | 223 awakable_list.CancelAll(); |
224 } // Join threads. | 224 } // Join threads. |
225 EXPECT_EQ(MOJO_RESULT_CANCELLED, result1); | 225 EXPECT_EQ(MOJO_RESULT_CANCELLED, result1); |
226 EXPECT_EQ(5u, context1); | 226 EXPECT_EQ(5u, context1); |
227 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); | 227 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); |
228 EXPECT_EQ(6u, context2); | 228 EXPECT_EQ(6u, context2); |
229 | 229 |
230 // Cancel one waiter, awake other for unsatisfiability. | 230 // Cancel one awakable, awake other for unsatisfiability. |
231 { | 231 { |
232 WaiterList waiter_list; | 232 AwakableList awakable_list; |
233 test::SimpleWaiterThread thread1(&result1, &context1); | 233 test::SimpleWaiterThread thread1(&result1, &context1); |
234 waiter_list.AddWaiter(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 7); | 234 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 7); |
235 thread1.Start(); | 235 thread1.Start(); |
236 | 236 |
237 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 237 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
238 | 238 |
239 // Should do nothing. | 239 // Should do nothing. |
240 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 240 awakable_list.AwakeForStateChange(HandleSignalsState( |
241 MOJO_HANDLE_SIGNAL_NONE, | 241 MOJO_HANDLE_SIGNAL_NONE, |
242 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 242 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
243 | 243 |
244 test::SimpleWaiterThread thread2(&result2, &context2); | 244 test::SimpleWaiterThread thread2(&result2, &context2); |
245 waiter_list.AddWaiter(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 8); | 245 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 8); |
246 thread2.Start(); | 246 thread2.Start(); |
247 | 247 |
248 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 248 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
249 | 249 |
250 // Awake #1. | 250 // Awake #1. |
251 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 251 awakable_list.AwakeForStateChange(HandleSignalsState( |
252 MOJO_HANDLE_SIGNAL_READABLE, | 252 MOJO_HANDLE_SIGNAL_READABLE, |
253 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); | 253 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
254 waiter_list.RemoveWaiter(thread1.waiter()); | 254 awakable_list.Remove(thread1.waiter()); |
255 | 255 |
256 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 256 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
257 | 257 |
258 test::SimpleWaiterThread thread3(&result3, &context3); | 258 test::SimpleWaiterThread thread3(&result3, &context3); |
259 waiter_list.AddWaiter(thread3.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 9); | 259 awakable_list.Add(thread3.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 9); |
260 thread3.Start(); | 260 thread3.Start(); |
261 | 261 |
262 test::SimpleWaiterThread thread4(&result4, &context4); | 262 test::SimpleWaiterThread thread4(&result4, &context4); |
263 waiter_list.AddWaiter(thread4.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 10); | 263 awakable_list.Add(thread4.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 10); |
264 thread4.Start(); | 264 thread4.Start(); |
265 | 265 |
266 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 266 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
267 | 267 |
268 // Awake #2 and #3 for unsatisfiability. | 268 // Awake #2 and #3 for unsatisfiability. |
269 waiter_list.AwakeWaitersForStateChange(HandleSignalsState( | 269 awakable_list.AwakeForStateChange(HandleSignalsState( |
270 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_READABLE)); | 270 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_READABLE)); |
271 waiter_list.RemoveWaiter(thread2.waiter()); | 271 awakable_list.Remove(thread2.waiter()); |
272 waiter_list.RemoveWaiter(thread3.waiter()); | 272 awakable_list.Remove(thread3.waiter()); |
273 | 273 |
274 // Cancel #4. | 274 // Cancel #4. |
275 waiter_list.CancelAllWaiters(); | 275 awakable_list.CancelAll(); |
276 } // Join threads. | 276 } // Join threads. |
277 EXPECT_EQ(MOJO_RESULT_OK, result1); | 277 EXPECT_EQ(MOJO_RESULT_OK, result1); |
278 EXPECT_EQ(7u, context1); | 278 EXPECT_EQ(7u, context1); |
279 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); | 279 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); |
280 EXPECT_EQ(8u, context2); | 280 EXPECT_EQ(8u, context2); |
281 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3); | 281 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3); |
282 EXPECT_EQ(9u, context3); | 282 EXPECT_EQ(9u, context3); |
283 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4); | 283 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4); |
284 EXPECT_EQ(10u, context4); | 284 EXPECT_EQ(10u, context4); |
285 } | 285 } |
286 | 286 |
287 } // namespace | 287 } // namespace |
288 } // namespace system | 288 } // namespace system |
289 } // namespace mojo | 289 } // namespace mojo |
OLD | NEW |