Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: util/synchronization/semaphore.cc

Issue 797173003: win: implement Semaphore (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: pcheck Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/synchronization/semaphore.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/synchronization/semaphore.cc
diff --git a/util/synchronization/semaphore.cc b/util/synchronization/semaphore.cc
index d513fa0dd43981acc72b1ff155fa2d1e77616388..5f0a206adaa48fdf48e41221f35f2662a91053de 100644
--- a/util/synchronization/semaphore.cc
+++ b/util/synchronization/semaphore.cc
@@ -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) {
« no previous file with comments | « util/synchronization/semaphore.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698