25#ifndef __JOIN_SEMAPHORE_HPP__
26#define __JOIN_SEMAPHORE_HPP__
62 Semaphore (
const std::string& name,
size_t value = 0,
int oflag = O_CREAT, mode_t mode = 0644);
85 void post () noexcept;
90 void wait () noexcept;
103 template <class Rep, class Period>
106 struct timespec ts =
toTimespec (std::chrono::system_clock::now () + timeout);
109 lastError = std::make_error_code (
static_cast <std::errc
> (errno));
120 int value () noexcept;
166 void post () noexcept;
171 void wait () noexcept;
184 template <class Rep, class Period>
187 struct timespec ts =
toTimespec (std::chrono::system_clock::now () + timeout);
188 if (sem_timedwait (&_handle, &ts) == -1)
190 lastError = std::make_error_code (
static_cast <std::errc
> (errno));
201 int value () noexcept;
class used to protect shared data from being simultaneously accessed by multiple threads.
Definition semaphore.hpp:47
void wait() noexcept
decrements the internal counter or blocks until it can
Definition semaphore.cpp:99
Semaphore(const Semaphore &other)=delete
copy constructor.
sem_t _unnamed_handle
Definition semaphore.hpp:126
~Semaphore() noexcept
destroy instance.
Definition semaphore.cpp:67
sem_t * _named_handle
Definition semaphore.hpp:125
int value() noexcept
get semaphore value.
Definition semaphore.cpp:129
bool tryWait() noexcept
tries to decrement the internal counter without blocking.
Definition semaphore.cpp:115
Semaphore & operator=(const Semaphore &other)=delete
copy assignment operator.
void post() noexcept
increments the internal counter and unblocks acquirers.
Definition semaphore.cpp:83
Semaphore(size_t value=0)
create an named semaphore.
Definition semaphore.cpp:41
bool timedWait(std::chrono::duration< Rep, Period > timeout)
tries to decrement the internal counter, blocking for up to a duration time.
Definition semaphore.hpp:104
class used to protect shared data from being simultaneously accessed by multiple process via a shared...
Definition semaphore.hpp:137
void post() noexcept
increments the internal counter and unblocks acquirers.
Definition semaphore.cpp:168
int value() noexcept
get semaphore value.
Definition semaphore.cpp:200
bool timedWait(std::chrono::duration< Rep, Period > timeout)
tries to decrement the internal counter, blocking for up to a duration time.
Definition semaphore.hpp:185
SharedSemaphore(const SharedSemaphore &other)=delete
copy constructor.
SharedSemaphore & operator=(const SharedSemaphore &other)=delete
copy assignment operator.
void wait() noexcept
decrements the internal counter or blocks until it can
Definition semaphore.cpp:177
bool tryWait() noexcept
tries to decrement the internal counter without blocking.
Definition semaphore.cpp:186
~SharedSemaphore() noexcept
destroy instance.
Definition semaphore.cpp:159
SharedSemaphore(size_t value=0)
create instance.
Definition semaphore.cpp:147
Definition acceptor.hpp:32
struct timespec toTimespec(std::chrono::time_point< Clock, Duration > timePoint)
converts time_point to timespec.
Definition utils.hpp:423