X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fpbd%2Fsemutils.cc;h=7f31d30fafca5d5d8c32629bb1695b089c99468e;hb=c80e8727dffd2a0958ae377aff5f0e7e2904770f;hp=48fdd249f60f9e8879ef1c69a26323ad1dcb0e76;hpb=1676789907b95aa8d5bf6cc2ce62aa66a80b9aae;p=ardour.git diff --git a/libs/pbd/semutils.cc b/libs/pbd/semutils.cc index 48fdd249f6..7f31d30faf 100644 --- a/libs/pbd/semutils.cc +++ b/libs/pbd/semutils.cc @@ -21,15 +21,20 @@ 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