Skip to content

Commit

Permalink
iox-eclipse-iceoryx#751 the platform IOX_SEM_VALUE_MAX is a constexpr…
Browse files Browse the repository at this point in the history
… to ensure type safety, fix gcc warning unused value

Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Jun 23, 2022
1 parent 3b371aa commit af640e1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ inline void Expect<Derived>::expect(const StringType& msg) const noexcept
{
// it is possible that expect is called inside a signal handler therefore we
// use write
IOX_DISCARD_RESULT(write(STDERR_FILENO, &msg[0], strlen(&msg[0])));
auto result = write(STDERR_FILENO, &msg[0], strlen(&msg[0]));
IOX_DISCARD_RESULT(result);
Ensures(false);
}
}
Expand All @@ -57,7 +58,8 @@ inline ValueType& ExpectWithValue<Derived, ValueType>::expect(const StringType&
{
// it is possible that expect is called inside a signal handler therefore we
// use write
IOX_DISCARD_RESULT(write(STDERR_FILENO, &msg[0], strlen(&msg[0])));
auto result = write(STDERR_FILENO, &msg[0], strlen(&msg[0]));
IOX_DISCARD_RESULT(result);
Ensures(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace posix
{
enum class SemaphoreError
{
INVALID_NAME,
INVALID_SEMAPHORE_HANDLE,
SEMAPHORE_OVERFLOW,
INTERRUPTED_BY_SIGNAL_HANDLER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NamedPipe : public DesignPattern::Creation<NamedPipe, IpcChannelError>
static constexpr uint64_t MAX_MESSAGE_SIZE = 4U * 1024U;
static constexpr uint32_t MAX_NUMBER_OF_MESSAGES = 10U;
static_assert(
MAX_NUMBER_OF_MESSAGES < 51,
MAX_NUMBER_OF_MESSAGES < IOX_SEM_VALUE_MAX,
"The maximum number of supported messages must be less or equal to the maximum allowed semaphore value");

static constexpr uint64_t NULL_TERMINATOR_SIZE = 0U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#ifndef IOX_HOOFS_LINUX_PLATFORM_SEMAPHORE_HPP
#define IOX_HOOFS_LINUX_PLATFORM_SEMAPHORE_HPP

#include <climits>
#include <cstdint>
#include <semaphore.h>

using iox_sem_t = sem_t;

#define IOX_SEM_FAILED SEM_FAILED
#define IOX_SEM_VALUE_MAX SEM_VALUE_MAX
constexpr uint32_t IOX_SEM_VALUE_MAX = SEM_VALUE_MAX;

inline int iox_sem_getvalue(iox_sem_t* sem, int* sval)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#define IOX_HOOFS_MAC_PLATFORM_SEMAPHORE_HPP

#include <atomic>
#include <cstdint>
#include <dispatch/dispatch.h>
#include <semaphore.h>

#define IOX_SEM_FAILED static_cast<iox_sem_t*>(nullptr)
#define IOX_SEM_VALUE_MAX SEM_VALUE_MAX
constexpr uint32_t IOX_SEM_VALUE_MAX = SEM_VALUE_MAX;

struct iox_sem_t
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef IOX_HOOFS_QNX_PLATFORM_SEMAPHORE_HPP
#define IOX_HOOFS_QNX_PLATFORM_SEMAPHORE_HPP

#include <cstdint>
#include <semaphore.h>

using iox_sem_t = sem_t;

#define IOX_SEM_FAILED SEM_FAILED
#define IOX_SEM_VALUE_MAX SEM_VALUE_MAX
constexpr uint32_t IOX_SEM_VALUE_MAX = SEM_VALUE_MAX;

inline int iox_sem_getvalue(iox_sem_t* sem, int* sval)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef IOX_HOOFS_UNIX_PLATFORM_SEMAPHORE_HPP
#define IOX_HOOFS_UNIX_PLATFORM_SEMAPHORE_HPP

#include <cstdint>
#include <semaphore.h>

using iox_sem_t = sem_t;

#define IOX_SEM_FAILED SEM_FAILED
#define IOX_SEM_VALUE_MAX SEM_VALUE_MAX
constexpr uint32_t IOX_SEM_VALUE_MAX = SEM_VALUE_MAX;

inline int iox_sem_getvalue(iox_sem_t* sem, int* sval)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "iceoryx_hoofs/platform/win32_errorHandling.hpp"
#include "iceoryx_hoofs/platform/windows.hpp"

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
Expand All @@ -34,7 +35,7 @@
#define IOX_SEM_FAILED static_cast<iox_sem_t*>(nullptr)
// win32 API page talks about maximum allowed value without defining it or how to obtain.
// We use the IOX_SEM_VALUE_MAX from linux which is INT_MAX
#define IOX_SEM_VALUE_MAX INT_MAX
constexpr uint32_t IOX_SEM_VALUE_MAX = INT_MAX;

struct iox_sem_t
{
Expand Down

0 comments on commit af640e1

Please sign in to comment.