Index: util/synchronization/semaphore_mac.cc |
diff --git a/util/synchronization/semaphore.cc b/util/synchronization/semaphore_mac.cc |
similarity index 53% |
copy from util/synchronization/semaphore.cc |
copy to util/synchronization/semaphore_mac.cc |
index 5f0a206adaa48fdf48e41221f35f2662a91053de..e8a79ab4c2dc2f58fc6fad1a8247cb705a9b7ec9 100644 |
--- a/util/synchronization/semaphore.cc |
+++ b/util/synchronization/semaphore_mac.cc |
@@ -14,15 +14,10 @@ |
#include "util/synchronization/semaphore.h" |
-#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"; |
@@ -36,50 +31,15 @@ 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, |
- std::numeric_limits<LONG>::max(), |
- nullptr)) { |
- PCHECK(semaphore_) << "CreateSemaphore"; |
-} |
- |
-Semaphore::~Semaphore() { |
- PCHECK(CloseHandle(semaphore_)); |
-} |
- |
-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); |
+ const dispatch_time_t timeout = |
+ dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC); |
+ return dispatch_semaphore_wait(semaphore_, timeout) == 0; |
} |
void Semaphore::Signal() { |
- PCHECK(sem_post(&semaphore_)) << "sem_post"; |
+ dispatch_semaphore_signal(semaphore_); |
} |
-#endif |
- |
} // namespace crashpad |