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/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
6 | 6 |
7 #include <malloc.h> | 7 #include <malloc.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // paths of allocator_shim.cc and smoke-test its thread safey. | 294 // paths of allocator_shim.cc and smoke-test its thread safey. |
295 // The test creates kNumThreads threads. Each of them does just a realloc(0x42). | 295 // The test creates kNumThreads threads. Each of them does just a realloc(0x42). |
296 // The shim intercepts such realloc and makes it fail only once on each thread. | 296 // The shim intercepts such realloc and makes it fail only once on each thread. |
297 // We expect to see excactly kNumThreads invocations of the new_handler. | 297 // We expect to see excactly kNumThreads invocations of the new_handler. |
298 TEST_F(AllocatorShimTest, NewHandlerConcurrency) { | 298 TEST_F(AllocatorShimTest, NewHandlerConcurrency) { |
299 const int kNumThreads = 32; | 299 const int kNumThreads = 32; |
300 PlatformThreadHandle threads[kNumThreads]; | 300 PlatformThreadHandle threads[kNumThreads]; |
301 | 301 |
302 // The WaitableEvent here is used to attempt to trigger all the threads at | 302 // The WaitableEvent here is used to attempt to trigger all the threads at |
303 // the same time, after they have been initialized. | 303 // the same time, after they have been initialized. |
304 WaitableEvent event(/*manual_reset=*/true, /*initially_signaled=*/false); | 304 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, |
| 305 WaitableEvent::InitialState::NOT_SIGNALED); |
305 | 306 |
306 ThreadDelegateForNewHandlerTest mock_thread_main(&event); | 307 ThreadDelegateForNewHandlerTest mock_thread_main(&event); |
307 | 308 |
308 for (int i = 0; i < kNumThreads; ++i) | 309 for (int i = 0; i < kNumThreads; ++i) |
309 PlatformThread::Create(0, &mock_thread_main, &threads[i]); | 310 PlatformThread::Create(0, &mock_thread_main, &threads[i]); |
310 | 311 |
311 std::set_new_handler(&AllocatorShimTest::NewHandler); | 312 std::set_new_handler(&AllocatorShimTest::NewHandler); |
312 SetCallNewHandlerOnMallocFailure(true); // It's going to fail on realloc(). | 313 SetCallNewHandlerOnMallocFailure(true); // It's going to fail on realloc(). |
313 InsertAllocatorDispatch(&g_mock_dispatch); | 314 InsertAllocatorDispatch(&g_mock_dispatch); |
314 event.Signal(); | 315 event.Signal(); |
315 for (int i = 0; i < kNumThreads; ++i) | 316 for (int i = 0; i < kNumThreads; ++i) |
316 PlatformThread::Join(threads[i]); | 317 PlatformThread::Join(threads[i]); |
317 RemoveAllocatorDispatchForTesting(&g_mock_dispatch); | 318 RemoveAllocatorDispatchForTesting(&g_mock_dispatch); |
318 ASSERT_EQ(kNumThreads, GetNumberOfNewHandlerCalls()); | 319 ASSERT_EQ(kNumThreads, GetNumberOfNewHandlerCalls()); |
319 } | 320 } |
320 | 321 |
321 } // namespace | 322 } // namespace |
322 } // namespace allocator | 323 } // namespace allocator |
323 } // namespace base | 324 } // namespace base |
OLD | NEW |