| Index: util/synchronization/semaphore_win.cc
|
| diff --git a/util/synchronization/semaphore.cc b/util/synchronization/semaphore_win.cc
|
| similarity index 60%
|
| rename from util/synchronization/semaphore.cc
|
| rename to util/synchronization/semaphore_win.cc
|
| index 5f0a206adaa48fdf48e41221f35f2662a91053de..962c7baeac6aa09a4aad20dbab982d7acfba7820 100644
|
| --- a/util/synchronization/semaphore.cc
|
| +++ b/util/synchronization/semaphore_win.cc
|
| @@ -17,31 +17,9 @@
|
| #include <limits>
|
|
|
| #include "base/logging.h"
|
| -#include "base/posix/eintr_wrapper.h"
|
|
|
| namespace crashpad {
|
|
|
| -#if defined(OS_MACOSX)
|
| -
|
| -Semaphore::Semaphore(int value)
|
| - : semaphore_(dispatch_semaphore_create(value)) {
|
| - CHECK(semaphore_) << "dispatch_semaphore_create";
|
| -}
|
| -
|
| -Semaphore::~Semaphore() {
|
| - dispatch_release(semaphore_);
|
| -}
|
| -
|
| -void Semaphore::Wait() {
|
| - CHECK_EQ(dispatch_semaphore_wait(semaphore_, DISPATCH_TIME_FOREVER), 0);
|
| -}
|
| -
|
| -void Semaphore::Signal() {
|
| - dispatch_semaphore_signal(semaphore_);
|
| -}
|
| -
|
| -#elif defined(OS_WIN)
|
| -
|
| Semaphore::Semaphore(int value)
|
| : semaphore_(CreateSemaphore(nullptr,
|
| value,
|
| @@ -58,28 +36,15 @@ void Semaphore::Wait() {
|
| PCHECK(WaitForSingleObject(semaphore_, INFINITE) == WAIT_OBJECT_0);
|
| }
|
|
|
| -void Semaphore::Signal() {
|
| - PCHECK(ReleaseSemaphore(semaphore_, 1, nullptr));
|
| -}
|
| -
|
| -#else
|
| -
|
| -Semaphore::Semaphore(int value) {
|
| - PCHECK(sem_init(&semaphore_, 0, value) == 0) << "sem_init";
|
| -}
|
| -
|
| -Semaphore::~Semaphore() {
|
| - PCHECK(sem_destroy(&semaphore_)) << "sem_destroy";
|
| -}
|
| -
|
| -void Semaphore::Wait() {
|
| - PCHECK(HANDLE_EINTR(sem_wait(&semaphore_))) << "sem_wait";
|
| +bool Semaphore::TimedWait(double seconds) {
|
| + DCHECK_GE(seconds, 0.0);
|
| + DWORD rv = WaitForSingleObject(semaphore_, static_cast<DWORD>(seconds * 1E3));
|
| + PCHECK(rv == WAIT_OBJECT_0 || rv == WAIT_TIMEOUT) << "WaitForSingleObject";
|
| + return rv == WAIT_OBJECT_0;
|
| }
|
|
|
| void Semaphore::Signal() {
|
| - PCHECK(sem_post(&semaphore_)) << "sem_post";
|
| + PCHECK(ReleaseSemaphore(semaphore_, 1, nullptr));
|
| }
|
|
|
| -#endif
|
| -
|
| } // namespace crashpad
|
|
|