17 #ifndef IOX_UTILS_POSIX_WRAPPER_SEMAPHORE_HPP
18 #define IOX_UTILS_POSIX_WRAPPER_SEMAPHORE_HPP
20 #include "iceoryx_utils/cxx/expected.hpp"
21 #include "iceoryx_utils/cxx/helplets.hpp"
22 #include "iceoryx_utils/cxx/smart_c.hpp"
23 #include "iceoryx_utils/cxx/string.hpp"
24 #include "iceoryx_utils/design_pattern/creation.hpp"
25 #include "iceoryx_utils/internal/relocatable_pointer/relative_pointer.hpp"
26 #include "iceoryx_utils/internal/units/duration.hpp"
27 #include "iceoryx_utils/platform/fcntl.hpp"
28 #include "iceoryx_utils/platform/semaphore.hpp"
29 #include "iceoryx_utils/platform/stat.hpp"
37 enum class SemaphoreError
42 UNABLE_TO_OPEN_HANDLE,
43 INVALID_SEMAPHORE_HANDLE,
45 INTERRUPTED_BY_SIGNAL_HANDLER,
49 enum class SemaphoreWaitState
123 cxx::expected<
int, SemaphoreError>
getValue() const noexcept;
132 cxx::expected<SemaphoreError>
post() noexcept;
144 cxx::expected<SemaphoreWaitState, SemaphoreError>
timedWait(const units::Duration abs_timeout,
145 const
bool doContinueOnInterrupt) const noexcept;
150 cxx::expected<
bool, SemaphoreError>
tryWait() const noexcept;
179 cxx::expected<SemaphoreError>
wait() const noexcept;
186 cxx::
string<128> m_name;
187 bool m_isCreated = true;
188 bool m_isNamedSemaphore = true;
189 bool m_isShared = false;
191 mutable iox_sem_t m_handle;
192 mutable
iox::rp::RelativePointer<iox_sem_t> m_handlePtr = &m_handle;
195 friend class DesignPattern::Creation<
Semaphore, SemaphoreError>;
244 bool close() noexcept;
260 bool destroy() noexcept;
286 bool init(iox_sem_t* handle, const
int pshared, const
unsigned int value) noexcept;
314 bool open(const
int oflag) noexcept;
316 bool open(const
int oflag, const mode_t mode, const
unsigned int value) noexcept;
325 bool unlink(const
char* name) noexcept;
329 bool isNamedSemaphore() noexcept;
331 void closeHandle() noexcept;
333 template <typename SmartC>
334 bool setHandleFromCall(const SmartC& call) noexcept;
336 SemaphoreError errnoToEnum(const
int errnoValue) const noexcept;
341 #include "iceoryx_utils/internal/posix_wrapper/semaphore.inl"
This pattern can be used if you write an abstraction where you have to throw an exception in the cons...
Definition: creation.hpp:99
Posix semaphore C++ Wrapping class.
Definition: semaphore.hpp:84
cxx::expected< bool, SemaphoreError > tryWait() const noexcept
see wait()
cxx::expected< SemaphoreError > post() noexcept
calls sem_post which unlocks a semaphore From the sem_post manpage: sem_post() increments (unlocks) t...
Semaphore() noexcept
Default constructor which creates an uninitialized semaphore. This semaphore object is unusable you n...
iox_sem_t * getHandle() noexcept
returns the pointer to the managed semaphore. You can use this pointer with all the sem_** functions.
cxx::expected< SemaphoreWaitState, SemaphoreError > timedWait(const units::Duration abs_timeout, const bool doContinueOnInterrupt) const noexcept
see wait()
cxx::expected< SemaphoreError > wait() const noexcept
calls sem_wait which locks a semaphore From the sem_wait manpage: sem_wait() decrements (locks) the s...
cxx::expected< int, SemaphoreError > getValue() const noexcept
calls sem_getvalue which gets the value of a semaphore From the sem_getvalue manpage: sem_getvalue() ...
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
Definition: semaphore.hpp:62
Definition: semaphore.hpp:59
Definition: semaphore.hpp:56
Definition: semaphore.hpp:65