mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-08 21:26:04 +00:00
win: implement Semaphore
Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686946%28v=vs.85%29.aspx R=mark@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/797173003
This commit is contained in:
parent
ec38bf152d
commit
d1fdcf99e0
@ -14,6 +14,8 @@
|
||||
|
||||
#include "util/synchronization/semaphore.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
|
||||
@ -38,6 +40,28 @@ 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) {
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include <dispatch/dispatch.h>
|
||||
#elif defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
@ -53,6 +55,8 @@ class Semaphore {
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
dispatch_semaphore_t semaphore_;
|
||||
#elif defined(OS_WIN)
|
||||
HANDLE semaphore_;
|
||||
#else
|
||||
sem_t semaphore_;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user