Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1755 Use platform log frontend everywhere on macO…
Browse files Browse the repository at this point in the history
…S platform
  • Loading branch information
elBoberido committed Mar 11, 2024
1 parent e687c49 commit 6a4715e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions iceoryx_platform/mac/source/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_platform/semaphore.hpp"
#include "iceoryx_platform/logging.hpp"
#include "iceoryx_platform/time.hpp"

#include <chrono>
#include <cstdarg>
#include <cstdlib>
#include <iostream>
#include <thread>

iox_sem_t::iox_sem_t() noexcept
Expand Down Expand Up @@ -54,9 +54,9 @@ int iox_sem_getvalue(iox_sem_t* sem, int* sval)
{
if (sem->m_hasPosixHandle)
{
std::cerr
<< "\"sem_getvalue\" is not supported for named semaphores on MacOS and always returns 0, do not use it!"
<< std::endl;
IOX_PLATFORM_LOG(
IOX_PLATFORM_LOG_LEVEL_ERROR,
"\"sem_getvalue\" is not supported for named semaphores on MacOS and always returns 0, do not use it!");
return 0;
}
*sval = static_cast<int>(sem->m_value.load(std::memory_order_relaxed));
Expand Down Expand Up @@ -245,14 +245,14 @@ int iox_sem_init(iox_sem_t* sem, int, unsigned int value)
pthread_mutexattr_t mutexAttr;
if (pthread_mutexattr_init(&mutexAttr) != 0)
{
printf("failed to initialize mutexattr\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "failed to initialize mutexattr");
return -1;
}

if (pthread_mutexattr_setpshared(&mutexAttr, PTHREAD_PROCESS_SHARED) != 0)
{
pthread_mutexattr_destroy(&mutexAttr);
printf("unable to set the shared process mutex attribute\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "unable to set the shared process mutex attribute\n");
return -1;
}

Expand All @@ -261,23 +261,24 @@ int iox_sem_init(iox_sem_t* sem, int, unsigned int value)
if (pthread_condattr_init(&condAttr) != 0)
{
pthread_mutexattr_destroy(&mutexAttr);
printf("failed to initialize condattr\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "failed to initialize condattr\n");
return -1;
}

if (pthread_condattr_setpshared(&condAttr, PTHREAD_PROCESS_SHARED) != 0)
{
pthread_condattr_destroy(&condAttr);
pthread_mutexattr_destroy(&mutexAttr);
printf("unable to set the shared process condition variable attribute\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR,
"unable to set the shared process condition variable attribute\n");
return -1;
}

if (pthread_mutex_init(&sem->m_handle.condition.mtx, &mutexAttr) != 0)
{
pthread_condattr_destroy(&condAttr);
pthread_mutexattr_destroy(&mutexAttr);
printf("failed to initialize inter process mutex\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "failed to initialize inter process mutex\n");
return -1;
}

Expand All @@ -286,7 +287,7 @@ int iox_sem_init(iox_sem_t* sem, int, unsigned int value)
pthread_mutex_destroy(&sem->m_handle.condition.mtx);
pthread_condattr_destroy(&condAttr);
pthread_mutexattr_destroy(&mutexAttr);
printf("failed to initialize inter process condition variable\n");
IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "failed to initialize inter process condition variable\n");
return -1;
}

Expand Down

0 comments on commit 6a4715e

Please sign in to comment.