17#ifndef IOX_HOOFS_POSIX_WRAPPER_SEMAPHORE_HPP
18#define IOX_HOOFS_POSIX_WRAPPER_SEMAPHORE_HPP
20#include "iceoryx_hoofs/cxx/expected.hpp"
21#include "iceoryx_hoofs/cxx/helplets.hpp"
22#include "iceoryx_hoofs/cxx/string.hpp"
23#include "iceoryx_hoofs/design_pattern/creation.hpp"
24#include "iceoryx_hoofs/internal/relocatable_pointer/relative_pointer.hpp"
25#include "iceoryx_hoofs/internal/units/duration.hpp"
26#include "iceoryx_hoofs/platform/fcntl.hpp"
27#include "iceoryx_hoofs/platform/semaphore.hpp"
28#include "iceoryx_hoofs/platform/stat.hpp"
36enum class SemaphoreError
40 UNABLE_TO_OPEN_HANDLE,
41 INVALID_SEMAPHORE_HANDLE,
43 INTERRUPTED_BY_SIGNAL_HANDLER,
47enum class SemaphoreWaitState
121 cxx::expected<
int, SemaphoreError>
getValue() const noexcept;
130 cxx::expected<SemaphoreError>
post() noexcept;
136 cxx::expected<SemaphoreWaitState, SemaphoreError>
timedWait(const units::Duration abs_timeout) noexcept;
141 cxx::expected<
bool, SemaphoreError>
tryWait() noexcept;
170 cxx::expected<SemaphoreError>
wait() noexcept;
173 cxx::
string<128> m_name;
174 bool m_isCreated = true;
175 bool m_isNamedSemaphore = true;
176 bool m_isShared = false;
178 mutable iox_sem_t m_handle{};
179 mutable iox_sem_t* m_handlePtr =
nullptr;
229 bool close() noexcept;
245 bool destroy() noexcept;
271 static
bool init(iox_sem_t* handle, const
int pshared, const
unsigned int value) noexcept;
299 bool open(const
int oflag) noexcept;
303 iox_sem_t* getHandle() const noexcept;
305 bool open(const
int oflag, const mode_t mode, const
unsigned int value) noexcept;
314 static
bool unlink(const
char* name) noexcept;
318 bool isNamedSemaphore() const noexcept;
320 void closeHandle() noexcept;
322 static SemaphoreError errnoToEnum(const
int errnoValue) noexcept;
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:82
cxx::expected< int, SemaphoreError > getValue() const noexcept
calls sem_getvalue which gets the value of a semaphore From the sem_getvalue manpage: sem_getvalue() ...
Semaphore() noexcept
Default constructor which creates an uninitialized semaphore. This semaphore object is unusable you n...
cxx::expected< bool, SemaphoreError > tryWait() noexcept
see wait()
cxx::expected< SemaphoreError > wait() noexcept
calls sem_wait which locks a semaphore From the sem_wait manpage: sem_wait() decrements (locks) the s...
cxx::expected< SemaphoreWaitState, SemaphoreError > timedWait(const units::Duration abs_timeout) 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...
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29
Definition: semaphore.hpp:60
Definition: semaphore.hpp:57
Definition: semaphore.hpp:54
Definition: semaphore.hpp:63