Spelling correction patch from Debian
[ardour.git] / libs / pbd / semutils.cc
index 48fdd249f60f9e8879ef1c69a26323ad1dcb0e76..7f31d30fafca5d5d8c32629bb1695b089c99468e 100644 (file)
 
 using namespace PBD;
 
-ProcessSemaphore::ProcessSemaphore (const char* name, int val)
+Semaphore::Semaphore (const char* name, int val)
 {
-#ifdef __APPLE__
+#ifdef WINDOWS_SEMAPHORE
+       if ((_sem = CreateSemaphore(NULL, val, 32767, name)) == NULL) {
+               throw failed_constructor ();
+       }
+
+#elif __APPLE__
        if ((_sem = sem_open (name, O_CREAT, 0600, val)) == (sem_t*) SEM_FAILED) {
                throw failed_constructor ();
        }
 
        /* this semaphore does not exist for IPC */
-       
+
        if (sem_unlink (name)) {
                throw failed_constructor ();
        }
@@ -43,9 +48,30 @@ ProcessSemaphore::ProcessSemaphore (const char* name, int val)
 #endif
 }
 
-ProcessSemaphore::~ProcessSemaphore ()
+Semaphore::~Semaphore ()
 {
-#ifdef __APPLE__
+#ifdef WINDOWS_SEMAPHORE
+       CloseHandle(_sem);
+#elif __APPLE__
        sem_close (ptr_to_sem());
 #endif
 }
+
+#ifdef WINDOWS_SEMAPHORE
+
+int
+Semaphore::signal ()
+{
+       // non-zero on success, opposite to posix
+       return !ReleaseSemaphore(_sem, 1, NULL);
+}
+
+int
+Semaphore::wait ()
+{
+       DWORD result = 0;
+       result = WaitForSingleObject(_sem, INFINITE);
+       return (result == WAIT_OBJECT_0);
+}
+
+#endif