Skip to content

Commit

Permalink
iox-eclipse-iceoryx#751 Remove old semaphore and use the new unnamed …
Browse files Browse the repository at this point in the history
…semaphore in the signal watcher and the named pipe

Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Jun 23, 2022
1 parent 9a4fb4c commit 6589841
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 1,054 deletions.
1 change: 0 additions & 1 deletion iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ iox_add_library(
source/posix_wrapper/named_pipe.cpp
source/posix_wrapper/named_semaphore.cpp
source/posix_wrapper/posix_access_rights.cpp
source/posix_wrapper/semaphore.cpp
source/posix_wrapper/semaphore_interface.cpp
source/posix_wrapper/shared_memory_object.cpp
source/posix_wrapper/shared_memory_object/allocator.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,34 @@
#include "iceoryx_hoofs/cxx/expected.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/platform/semaphore.hpp"
#include "iceoryx_hoofs/posix_wrapper/semaphore.hpp"

namespace iox
{
namespace posix
{
enum class SemaphoreError
{
CREATION_FAILED,
NAME_TOO_LONG,
UNABLE_TO_OPEN_HANDLE,
INVALID_SEMAPHORE_HANDLE,
SEMAPHORE_OVERFLOW,
INTERRUPTED_BY_SIGNAL_HANDLER,
INVALID_NAME,
PERMISSION_DENIED,
ALREADY_EXIST,
FILE_DESCRIPTOR_LIMIT_REACHED,
NO_SEMAPHORE_WITH_THAT_NAME_EXISTS,
OUT_OF_MEMORY,
UNDEFINED
};

enum class SemaphoreWaitState
{
TIMEOUT,
NO_TIMEOUT,
};

namespace internal
{
/// @brief Defines the interface of a named and unnamed semaphore.
Expand Down
18 changes: 10 additions & 8 deletions iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/posix_wrapper/semaphore.hpp"
#include "iceoryx_hoofs/platform/semaphore.hpp"
#include "iceoryx_hoofs/posix_wrapper/unnamed_semaphore.hpp"

#include <cstdint>

Expand All @@ -36,7 +37,10 @@ class NamedPipe : public DesignPattern::Creation<NamedPipe, IpcChannelError>
// no system restrictions at all, except available memory. MAX_MESSAGE_SIZE and MAX_NUMBER_OF_MESSAGES can be
// increased as long as there is enough memory available
static constexpr uint64_t MAX_MESSAGE_SIZE = 4U * 1024U;
static constexpr uint64_t MAX_NUMBER_OF_MESSAGES = 10U;
static constexpr uint32_t MAX_NUMBER_OF_MESSAGES = 10U;
static_assert(
MAX_NUMBER_OF_MESSAGES < 51,
"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;
static constexpr units::Duration CYCLE_TIME = units::Duration::fromMilliseconds(10);
Expand Down Expand Up @@ -122,16 +126,15 @@ class NamedPipe : public DesignPattern::Creation<NamedPipe, IpcChannelError>
class NamedPipeData
{
public:
NamedPipeData(bool& isInitialized, IpcChannelError& error, const uint64_t maxMsgNumber) noexcept;
NamedPipeData(bool& isInitialized, IpcChannelError& error, const uint32_t maxMsgNumber) noexcept;
NamedPipeData(const NamedPipeData&) = delete;
NamedPipeData(NamedPipeData&& rhs) = delete;
~NamedPipeData() noexcept;

NamedPipeData& operator=(const NamedPipeData&) = delete;
NamedPipeData& operator=(NamedPipeData&& rhs) = delete;

Semaphore& sendSemaphore() noexcept;
Semaphore& receiveSemaphore() noexcept;
UnnamedSemaphore& sendSemaphore() noexcept;
UnnamedSemaphore& receiveSemaphore() noexcept;

bool waitForInitialization() const noexcept;
bool hasValidState() const noexcept;
Expand All @@ -148,8 +151,7 @@ class NamedPipe : public DesignPattern::Creation<NamedPipe, IpcChannelError>
static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1);

std::atomic<uint64_t> initializationGuard{INVALID_DATA};
using semaphoreMemory_t = uint8_t[sizeof(Semaphore)];
alignas(Semaphore) semaphoreMemory_t semaphores[2U];
cxx::optional<UnnamedSemaphore> semaphores[2U];
};


Expand Down
Loading

0 comments on commit 6589841

Please sign in to comment.