iceoryx_hoofs 2.0.5
|
Posix semaphore C++ Wrapping class. More...
#include <iceoryx_hoofs/posix_wrapper/semaphore.hpp>
Public Member Functions | |
Semaphore () noexcept | |
Default constructor which creates an uninitialized semaphore. This semaphore object is unusable you need to reassign it with an object created by the semaphore factory methods. | |
Semaphore (Semaphore &&rhs) noexcept | |
Move constructor. | |
Semaphore & | operator= (Semaphore &&rhs) noexcept |
Move assignment operator. | |
Semaphore (const Semaphore &)=delete | |
We are denying Semaphore copy since it manages the semaphore resource and the underlying concept did not include copying. | |
Semaphore & | operator= (const Semaphore &)=delete |
We are denying Semaphore copy since it manages the semaphore resource and the underlying concept did not include copying. | |
~Semaphore () noexcept | |
Destructor. | |
cxx::expected< int, SemaphoreError > | getValue () const noexcept |
calls sem_getvalue which gets the value of a semaphore From the sem_getvalue manpage: sem_getvalue() places the current value of the semaphore pointed to sem into the integer pointed to by sval. | |
cxx::expected< SemaphoreError > | post () noexcept |
calls sem_post which unlocks a semaphore From the sem_post manpage: sem_post() increments (unlocks) the semaphore pointed to by sem. If the semaphore's value consequently becomes greater than zero, then another process or thread blocked in a sem_wait(3) call will be woken up and proceed to lock the semaphore. | |
cxx::expected< SemaphoreWaitState, SemaphoreError > | timedWait (const units::Duration abs_timeout) noexcept |
see wait() | |
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 semaphore pointed to by sem. If the semaphore's value is greater than zero, then the decrement proceeds, and the function returns, immediately. If the semaphore currently has the value zero, then the call blocks until either it becomes possible to perform the decrement (i.e., the semaphore value rises above zero), or a signal handler interrupts the call. | |
![]() | |
Creation (Creation &&rhs) noexcept | |
Creation (const Creation &rhs) noexcept=default | |
Creation & | operator= (Creation &&rhs) noexcept |
Creation & | operator= (const Creation &rhs) noexcept=default |
bool | isInitialized () const noexcept |
returns true if the object was constructed successfully, otherwise false | |
Friends | |
class | DesignPattern::Creation< Semaphore, SemaphoreError > |
Additional Inherited Members | |
![]() | |
using | CreationPattern_t = Creation< Semaphore, SemaphoreError > |
using | result_t = iox::cxx::expected< Semaphore, SemaphoreError > |
using | errorType_t = SemaphoreError |
![]() | |
static result_t | create (Targs &&... args) noexcept |
factory method which guarantees that either a working object is produced or an error value describing the error during construction | |
static result_t | verify (Semaphore &&newObject) noexcept |
verifies if a class was created successfully | |
static iox::cxx::expected< SemaphoreError > | placementCreate (void *const memory, Targs &&... args) noexcept |
factory method which guarantees that either a working object is produced or an error value describing the error during construction | |
![]() | |
bool | m_isInitialized |
SemaphoreError | m_errorValue |
Posix semaphore C++ Wrapping class.
|
noexcept |
calls sem_getvalue which gets the value of a semaphore From the sem_getvalue manpage: sem_getvalue() places the current value of the semaphore pointed to sem into the integer pointed to by sval.
If one or more processes or threads are blocked waiting to lock the semaphore with sem_wait(3), POSIX.1 permits two possibilities for the value returned in sval: either 0 is returned; or a negative number whose absolute value is the count of the number of processes and threads currently blocked in sem_wait(3). Linux adopts the former behavior.
[in] | value | reference in which the value of the semaphore is written to |
|
noexcept |
calls sem_post which unlocks a semaphore From the sem_post manpage: sem_post() increments (unlocks) the semaphore pointed to by sem. If the semaphore's value consequently becomes greater than zero, then another process or thread blocked in a sem_wait(3) call will be woken up and proceed to lock the semaphore.
|
noexcept |
see wait()
[in] | abs_timeout | timeout of the wait |
|
noexcept |
see wait()
|
noexcept |
calls sem_wait which locks a semaphore From the sem_wait manpage: sem_wait() decrements (locks) the semaphore pointed to by sem. If the semaphore's value is greater than zero, then the decrement proceeds, and the function returns, immediately. If the semaphore currently has the value zero, then the call blocks until either it becomes possible to perform the decrement (i.e., the semaphore value rises above zero), or a signal handler interrupts the call.
iox_sem_trywait() is the same as sem_wait(), except that if the decrement cannot be immediately performed, then call returns an error (errno set to EAGAIN) instead of blocking.
iox_sem_timedwait() is the same as sem_wait(), except that abs_timeout specifies a limit on the amount of time that the call should block if the decrement cannot be immediately performed.
If the timeout has already expired by the time of the call, and the semaphore could not be locked immediately, then iox_sem_timedwait() fails with a timeout error (errno set to ETIMEDOUT).
If the operation can be performed immediately, then iox_sem_timedwait() never fails with a timeout error, regardless of the value of abs_timeout. Furthermore, the validity of abs_timeout is not checked in this case.