| Index: third_party/crashpad/crashpad/snapshot/win/crashpad_snapshot_test_image_reader.cc
|
| diff --git a/third_party/crashpad/crashpad/snapshot/win/crashpad_snapshot_test_image_reader.cc b/third_party/crashpad/crashpad/snapshot/win/crashpad_snapshot_test_image_reader.cc
|
| index a114d392e16c89962ef53501d96b5e091a695fca..6f4203d6c14a6d6c976875965e13b92f42872abe 100644
|
| --- a/third_party/crashpad/crashpad/snapshot/win/crashpad_snapshot_test_image_reader.cc
|
| +++ b/third_party/crashpad/crashpad/snapshot/win/crashpad_snapshot_test_image_reader.cc
|
| @@ -17,10 +17,14 @@
|
| #include "base/logging.h"
|
| #include "client/crashpad_info.h"
|
| #include "util/file/file_io.h"
|
| +#include "util/synchronization/semaphore.h"
|
| #include "util/win/scoped_handle.h"
|
|
|
| +namespace {
|
| +
|
| DWORD WINAPI LotsOfReferencesThreadProc(void* param) {
|
| - LONG* count = reinterpret_cast<LONG*>(param);
|
| + crashpad::Semaphore* semaphore =
|
| + reinterpret_cast<crashpad::Semaphore*>(param);
|
|
|
| // Allocate a bunch of pointers to things on the stack.
|
| int* pointers[1000];
|
| @@ -28,28 +32,31 @@ DWORD WINAPI LotsOfReferencesThreadProc(void* param) {
|
| pointers[i] = new int[2048];
|
| }
|
|
|
| - InterlockedIncrement(count);
|
| + semaphore->Signal();
|
| Sleep(INFINITE);
|
| return 0;
|
| }
|
|
|
| +} // namespace
|
| +
|
| int wmain(int argc, wchar_t* argv[]) {
|
| CHECK_EQ(argc, 2);
|
|
|
| crashpad::ScopedKernelHANDLE done(CreateEvent(nullptr, true, false, argv[1]));
|
| + PCHECK(done.is_valid()) << "CreateEvent";
|
|
|
| PCHECK(LoadLibrary(L"crashpad_snapshot_test_image_reader_module.dll"))
|
| << "LoadLibrary";
|
|
|
| // Create threads with lots of stack pointers to memory. This is used to
|
| // verify the cap on pointed-to memory.
|
| - LONG thread_ready_count = 0;
|
| + crashpad::Semaphore semaphore(0);
|
| crashpad::ScopedKernelHANDLE threads[100];
|
| for (int i = 0; i < arraysize(threads); ++i) {
|
| threads[i].reset(CreateThread(nullptr,
|
| 0,
|
| &LotsOfReferencesThreadProc,
|
| - reinterpret_cast<void*>(&thread_ready_count),
|
| + reinterpret_cast<void*>(&semaphore),
|
| 0,
|
| nullptr));
|
| if (!threads[i].is_valid()) {
|
| @@ -58,14 +65,8 @@ int wmain(int argc, wchar_t* argv[]) {
|
| }
|
| }
|
|
|
| - for (;;) {
|
| - if (InterlockedCompareExchange(&thread_ready_count,
|
| - arraysize(threads),
|
| - arraysize(threads) == arraysize(threads))) {
|
| - // All threads have allocated their references.
|
| - break;
|
| - }
|
| - Sleep(10);
|
| + for (int i = 0; i < arraysize(threads); ++i) {
|
| + semaphore.Wait();
|
| }
|
|
|
| crashpad::CrashpadInfo* crashpad_info =
|
| @@ -80,8 +81,8 @@ int wmain(int argc, wchar_t* argv[]) {
|
| crashpad::CheckedWriteFile(out, &c, sizeof(c));
|
|
|
| // Parent process says we can exit.
|
| - CHECK_EQ(WAIT_OBJECT_0, WaitForSingleObject(done.get(), INFINITE));
|
| + PCHECK(WaitForSingleObject(done.get(), INFINITE) == WAIT_OBJECT_0)
|
| + << "WaitForSingleObject";
|
|
|
| return 0;
|
| }
|
| -
|
|
|