diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp index 43d8cf02bb4..da526e8aaa8 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp @@ -170,10 +170,6 @@ class Semaphore : public DesignPattern::Creation /// @return if an error during the call occurs the error value is set cxx::expected wait() noexcept; - /// @brief returns the pointer to the managed semaphore. You can use this - /// pointer with all the sem_** functions. - iox_sem_t* getHandle() const noexcept; - private: cxx::string<128> m_name; bool m_isCreated = true; @@ -199,8 +195,6 @@ class Semaphore : public DesignPattern::Creation /// For details see man sem_init. /// @param[in] value initial value of the semaphore Semaphore(CreateUnnamedSharedMemorySemaphore_t, const unsigned int value) noexcept; - /// @deprecated do not use this constructor - Semaphore(CreateUnnamedSharedMemorySemaphore_t, iox_sem_t* handle, const unsigned int value) noexcept; /// @brief Opens an already existing named semaphore. If a semaphore with /// name does not exist an uninitialized Semaphore is returned @@ -305,6 +299,10 @@ class Semaphore : public DesignPattern::Creation /// @return returns false when sem_open fails otherwise true bool open(const int oflag) noexcept; + /// @brief returns the pointer to the managed semaphore. You can use this + /// pointer with all the sem_** functions. + iox_sem_t* getHandle() const noexcept; + bool open(const int oflag, const mode_t mode, const unsigned int value) noexcept; /// @brief calls sem_unlink which removes a named semaphore diff --git a/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp b/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp index bd71b6031ef..6d7fa110dc7 100644 --- a/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp @@ -115,34 +115,6 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, } } -NamedPipe::NamedPipeData::NamedPipeData(bool& isInitialized, - IpcChannelError& error, - const uint64_t maxMsgNumber) noexcept -{ - auto signalError = [&](const char* name) { - std::cerr << "Unable to create " << name << " semaphore for named pipe \"" << 'x' << "\""; - isInitialized = false; - error = IpcChannelError::INTERNAL_LOGIC_ERROR; - }; - - Semaphore::placementCreate( - &semaphores[SEND_SEMAPHORE], CreateUnnamedSharedMemorySemaphore, static_cast(maxMsgNumber)) - .or_else([&](auto) { signalError("send"); }); - - Semaphore::placementCreate(&semaphores[RECEIVE_SEMAPHORE], CreateUnnamedSharedMemorySemaphore, 0U) - .or_else([&](auto) { signalError("receive"); }); -} - -Semaphore& NamedPipe::NamedPipeData::sendSemaphore() noexcept -{ - return reinterpret_cast(semaphores[SEND_SEMAPHORE]); -} - -Semaphore& NamedPipe::NamedPipeData::receiveSemaphore() noexcept -{ - return reinterpret_cast(semaphores[RECEIVE_SEMAPHORE]); -} - NamedPipe::NamedPipe(NamedPipe&& rhs) noexcept { *this = std::move(rhs); @@ -340,6 +312,33 @@ cxx::expected NamedPipe::timedReceive(const units: return cxx::error(IpcChannelError::TIMEOUT); } +NamedPipe::NamedPipeData::NamedPipeData(bool& isInitialized, + IpcChannelError& error, + const uint64_t maxMsgNumber) noexcept +{ + auto signalError = [&](const char* name) { + std::cerr << "Unable to create " << name << " semaphore for named pipe \"" << 'x' << "\""; + isInitialized = false; + error = IpcChannelError::INTERNAL_LOGIC_ERROR; + }; + + Semaphore::placementCreate( + &semaphores[SEND_SEMAPHORE], CreateUnnamedSharedMemorySemaphore, static_cast(maxMsgNumber)) + .or_else([&](auto) { signalError("send"); }); + + Semaphore::placementCreate(&semaphores[RECEIVE_SEMAPHORE], CreateUnnamedSharedMemorySemaphore, 0U) + .or_else([&](auto) { signalError("receive"); }); +} + +Semaphore& NamedPipe::NamedPipeData::sendSemaphore() noexcept +{ + return reinterpret_cast(semaphores[SEND_SEMAPHORE]); +} + +Semaphore& NamedPipe::NamedPipeData::receiveSemaphore() noexcept +{ + return reinterpret_cast(semaphores[RECEIVE_SEMAPHORE]); +} } // namespace posix } // namespace iox diff --git a/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp b/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp index 657c3aa8d6b..ab7fb766629 100644 --- a/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp @@ -187,22 +187,6 @@ Semaphore::Semaphore(CreateUnnamedSharedMemorySemaphore_t, const unsigned int va } } -Semaphore::Semaphore(CreateUnnamedSharedMemorySemaphore_t, iox_sem_t* handle, const unsigned int value) noexcept - : m_isNamedSemaphore(false) - , m_isShared(true) - , m_handlePtr(handle) -{ - if (init(handle, 1, value)) - { - m_isInitialized = true; - } - else - { - m_isInitialized = false; - m_errorValue = SemaphoreError::CREATION_FAILED; - } -} - Semaphore::Semaphore(OpenNamedSemaphore_t, const char* name, const int oflag) noexcept : m_isCreated(false) {