Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1755 Fix Windows semaphore bug
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Mar 11, 2024
1 parent 6a4715e commit a97ddbe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions iceoryx_platform/win/source/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int iox_sem_destroy(iox_sem_t* sem)
return 0;
}

static HANDLE sem_create_win32_semaphore(LONG value, LPCSTR name)
static Win32CallReturn<HANDLE> sem_create_win32_semaphore(LONG value, LPCSTR name)
{
SECURITY_ATTRIBUTES securityAttribute;
SECURITY_DESCRIPTOR securityDescriptor;
Expand All @@ -180,24 +180,23 @@ static HANDLE sem_create_win32_semaphore(LONG value, LPCSTR name)
securityAttribute.lpSecurityDescriptor = &securityDescriptor;
securityAttribute.bInheritHandle = FALSE;

HANDLE returnValue = Win32Call(CreateSemaphoreA, &securityAttribute, value, IOX_SEM_VALUE_MAX, name).value;
return returnValue;
return Win32Call(CreateSemaphoreA, &securityAttribute, value, IOX_SEM_VALUE_MAX, name);
}

int iox_sem_init(iox_sem_t* sem, int pshared, unsigned int value)
{
sem->isInterprocessSemaphore = (pshared == 1);
if (sem->isInterprocessSemaphore)
{
sem->handle = sem_create_win32_semaphore(value, generateSemaphoreName(sem->uniqueId).c_str());
sem->handle = sem_create_win32_semaphore(value, generateSemaphoreName(sem->uniqueId).c_str()).value;
if (sem->handle != nullptr)
{
IpcHandleManager::getInstance().addHandle(sem->uniqueId, OwnerShip::OWN, sem->handle);
}
}
else
{
sem->handle = sem_create_win32_semaphore(value, nullptr);
sem->handle = sem_create_win32_semaphore(value, nullptr).value;
}

return (sem->handle != nullptr) ? 0 : -1;
Expand Down Expand Up @@ -229,8 +228,9 @@ iox_sem_t* iox_sem_open_impl(const char* name, int oflag, ...) // mode_t mode, u
unsigned int value = va_arg(va, unsigned int);
va_end(va);

sem->handle = sem_create_win32_semaphore(value, name);
if (oflag & O_EXCL && GetLastError() == ERROR_ALREADY_EXISTS)
auto result = sem_create_win32_semaphore(value, name);
sem->handle = result.value;
if (oflag & O_EXCL && result.error == ERROR_ALREADY_EXISTS)
{
errno = EEXIST;
iox_sem_close(sem);
Expand Down

0 comments on commit a97ddbe

Please sign in to comment.