Skip to content

Commit 60f7116

Browse files
committed
Update Semaphore parameters for OpenSemaphore. Update CreateSemaphore parameters to LONG_MAX count instead of 1.
This will allow multi-threaded apps to trigger events without throwing an exception when the count has been reached.
1 parent 56f8c9e commit 60f7116

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

RemoteInput/Echo/Semaphore.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ int sem_timedwait(sem_t* sem, const struct timespec* timeout)
4141
#if defined(_WIN32) || defined(_WIN64)
4242
Semaphore::Semaphore(std::int32_t count)
4343
{
44-
hSemaphore = OpenSemaphore(0, false, nullptr);
44+
hSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS, false, nullptr);
4545
if (!hSemaphore)
4646
{
47-
hSemaphore = CreateSemaphore(nullptr, count, count + 1, nullptr);
47+
hSemaphore = CreateSemaphore(nullptr, count, LONG_MAX, nullptr);
4848
}
4949

5050
if (!hSemaphore)
@@ -55,10 +55,10 @@ Semaphore::Semaphore(std::int32_t count)
5555

5656
Semaphore::Semaphore(const std::string &name, std::int32_t count)
5757
{
58-
hSemaphore = OpenSemaphore(0, false, name.c_str());
58+
hSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS, false, name.c_str());
5959
if (!hSemaphore)
6060
{
61-
hSemaphore = CreateSemaphore(nullptr, count, count + 1, name.c_str());
61+
hSemaphore = CreateSemaphore(nullptr, count, LONG_MAX, name.c_str());
6262
}
6363

6464
if (!hSemaphore)

0 commit comments

Comments
 (0)