OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); | 167 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); |
168 --thread_info->suspend_count; | 168 --thread_info->suspend_count; |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 for (ThreadInfo* thread_info : thread_infos_) { | 172 for (ThreadInfo* thread_info : thread_infos_) { |
173 thread_info->exit_semaphore.Signal(); | 173 thread_info->exit_semaphore.Signal(); |
174 } | 174 } |
175 | 175 |
176 for (const ThreadInfo* thread_info : thread_infos_) { | 176 for (const ThreadInfo* thread_info : thread_infos_) { |
177 int rv = pthread_join(thread_info->pthread, NULL); | 177 int rv = pthread_join(thread_info->pthread, nullptr); |
178 CHECK_EQ(0, rv); | 178 CHECK_EQ(0, rv); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 // Starts |thread_count| threads and waits on each thread’s ready semaphore, | 182 // Starts |thread_count| threads and waits on each thread’s ready semaphore, |
183 // so that when this function returns, all threads have been started and have | 183 // so that when this function returns, all threads have been started and have |
184 // all run to the point that they’ve signalled that they are ready. | 184 // all run to the point that they’ve signalled that they are ready. |
185 void StartThreads(size_t thread_count) { | 185 void StartThreads(size_t thread_count) { |
186 ASSERT_TRUE(thread_infos_.empty()); | 186 ASSERT_TRUE(thread_infos_.empty()); |
187 | 187 |
188 for (size_t thread_index = 0; thread_index < thread_count; ++thread_index) { | 188 for (size_t thread_index = 0; thread_index < thread_count; ++thread_index) { |
189 ThreadInfo* thread_info = new ThreadInfo(); | 189 ThreadInfo* thread_info = new ThreadInfo(); |
190 thread_infos_.push_back(thread_info); | 190 thread_infos_.push_back(thread_info); |
191 | 191 |
192 int rv = pthread_create(&thread_info->pthread, | 192 int rv = pthread_create(&thread_info->pthread, |
193 NULL, | 193 nullptr, |
194 ThreadMain, | 194 ThreadMain, |
195 thread_info); | 195 thread_info); |
196 ASSERT_EQ(0, rv); | 196 ASSERT_EQ(0, rv); |
197 } | 197 } |
198 | 198 |
199 for (ThreadInfo* thread_info : thread_infos_) { | 199 for (ThreadInfo* thread_info : thread_infos_) { |
200 thread_info->ready_semaphore.Wait(); | 200 thread_info->ready_semaphore.Wait(); |
201 } | 201 } |
202 | 202 |
203 // If present, suspend the thread at indices 1 through 3 the same number of | 203 // If present, suspend the thread at indices 1 through 3 the same number of |
(...skipping 22 matching lines...) Expand all Loading... |
226 const ThreadInfo* thread_info = thread_infos_[thread_index]; | 226 const ThreadInfo* thread_info = thread_infos_[thread_index]; |
227 expectation->stack_address = thread_info->stack_address; | 227 expectation->stack_address = thread_info->stack_address; |
228 expectation->suspend_count = thread_info->suspend_count; | 228 expectation->suspend_count = thread_info->suspend_count; |
229 | 229 |
230 return PthreadToThreadID(thread_info->pthread); | 230 return PthreadToThreadID(thread_info->pthread); |
231 } | 231 } |
232 | 232 |
233 private: | 233 private: |
234 struct ThreadInfo { | 234 struct ThreadInfo { |
235 ThreadInfo() | 235 ThreadInfo() |
236 : pthread(NULL), | 236 : pthread(nullptr), |
237 stack_address(0), | 237 stack_address(0), |
238 ready_semaphore(0), | 238 ready_semaphore(0), |
239 exit_semaphore(0), | 239 exit_semaphore(0), |
240 suspend_count(0) { | 240 suspend_count(0) { |
241 } | 241 } |
242 | 242 |
243 ~ThreadInfo() {} | 243 ~ThreadInfo() {} |
244 | 244 |
245 // The thread’s ID, set at the time the thread is created. | 245 // The thread’s ID, set at the time the thread is created. |
246 pthread_t pthread; | 246 pthread_t pthread; |
(...skipping 25 matching lines...) Expand all Loading... |
272 | 272 |
273 thread_info->ready_semaphore.Signal(); | 273 thread_info->ready_semaphore.Signal(); |
274 thread_info->exit_semaphore.Wait(); | 274 thread_info->exit_semaphore.Wait(); |
275 | 275 |
276 // Check this here after everything’s known to be synchronized, otherwise | 276 // Check this here after everything’s known to be synchronized, otherwise |
277 // there’s a race between the parent thread storing this thread’s pthread_t | 277 // there’s a race between the parent thread storing this thread’s pthread_t |
278 // in thread_info_pthread and this thread starting and attempting to access | 278 // in thread_info_pthread and this thread starting and attempting to access |
279 // it. | 279 // it. |
280 CHECK_EQ(pthread_self(), thread_info->pthread); | 280 CHECK_EQ(pthread_self(), thread_info->pthread); |
281 | 281 |
282 return NULL; | 282 return nullptr; |
283 } | 283 } |
284 | 284 |
285 // This is a PointerVector because the address of a ThreadInfo object is | 285 // This is a PointerVector because the address of a ThreadInfo object is |
286 // passed to each thread’s ThreadMain(), so they cannot move around in memory. | 286 // passed to each thread’s ThreadMain(), so they cannot move around in memory. |
287 PointerVector<ThreadInfo> thread_infos_; | 287 PointerVector<ThreadInfo> thread_infos_; |
288 | 288 |
289 DISALLOW_COPY_AND_ASSIGN(TestThreadPool); | 289 DISALLOW_COPY_AND_ASSIGN(TestThreadPool); |
290 }; | 290 }; |
291 | 291 |
292 typedef std::map<uint64_t, TestThreadPool::ThreadExpectation> ThreadMap; | 292 typedef std::map<uint64_t, TestThreadPool::ThreadExpectation> ThreadMap; |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 }; | 683 }; |
684 | 684 |
685 TEST(ProcessReader, ChildModules) { | 685 TEST(ProcessReader, ChildModules) { |
686 ProcessReaderModulesChild process_reader_modules_child; | 686 ProcessReaderModulesChild process_reader_modules_child; |
687 process_reader_modules_child.Run(); | 687 process_reader_modules_child.Run(); |
688 } | 688 } |
689 | 689 |
690 } // namespace | 690 } // namespace |
691 } // namespace test | 691 } // namespace test |
692 } // namespace crashpad | 692 } // namespace crashpad |
OLD | NEW |