X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fsemutils.cc;h=cf7b54d30e2babd036853a29ebc87d2e284e48f1;hb=e97b7bb924bd4ae6a7ca2f3c1e19dafd5294718f;hp=48fdd249f60f9e8879ef1c69a26323ad1dcb0e76;hpb=1676789907b95aa8d5bf6cc2ce62aa66a80b9aae;p=ardour.git diff --git a/libs/pbd/semutils.cc b/libs/pbd/semutils.cc index 48fdd249f6..cf7b54d30e 100644 --- a/libs/pbd/semutils.cc +++ b/libs/pbd/semutils.cc @@ -23,7 +23,12 @@ using namespace PBD; ProcessSemaphore::ProcessSemaphore (const char* name, int val) { -#ifdef __APPLE__ +#ifdef PLATFORM_WINDOWS + 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 (); } @@ -45,7 +50,28 @@ ProcessSemaphore::ProcessSemaphore (const char* name, int val) ProcessSemaphore::~ProcessSemaphore () { -#ifdef __APPLE__ +#ifdef PLATFORM_WINDOWS + CloseHandle(_sem); +#elif __APPLE__ sem_close (ptr_to_sem()); #endif } + +#ifdef PLATFORM_WINDOWS + +int +ProcessSemaphore::signal () +{ + // non-zero on success, opposite to posix + return !ReleaseSemaphore(_sem, 1, NULL); +} + +int +ProcessSemaphore::wait () +{ + DWORD result = 0; + result = WaitForSingleObject(_sem, INFINITE); + return (result == WAIT_OBJECT_0); +} + +#endif