join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::Semaphore Class Reference

class used to protect shared data from being simultaneously accessed by multiple threads. More...

#include <semaphore.hpp>

Public Member Functions

 Semaphore (size_t value=0)
 create an named semaphore.
 
 Semaphore (const std::string &name, size_t value=0, int oflag=O_CREAT, mode_t mode=0644)
 create a named semaphore.
 
 Semaphore (const Semaphore &other)=delete
 copy constructor.
 
Semaphoreoperator= (const Semaphore &other)=delete
 copy assignment operator.
 
 ~Semaphore () noexcept
 destroy instance.
 
void post () noexcept
 increments the internal counter and unblocks acquirers.
 
void wait () noexcept
 decrements the internal counter or blocks until it can
 
bool tryWait () noexcept
 tries to decrement the internal counter without blocking.
 
template<class Rep , class Period >
bool timedWait (std::chrono::duration< Rep, Period > timeout)
 tries to decrement the internal counter, blocking for up to a duration time.
 
int value () noexcept
 get semaphore value.
 

Detailed Description

class used to protect shared data from being simultaneously accessed by multiple threads.

Constructor & Destructor Documentation

◆ Semaphore() [1/3]

Semaphore::Semaphore ( size_t value = 0)

create an named semaphore.

Parameters
valueintial value.

◆ Semaphore() [2/3]

Semaphore::Semaphore ( const std::string & name,
size_t value = 0,
int oflag = O_CREAT,
mode_t mode = 0644 )

create a named semaphore.

Parameters
namesemaphore name.
valueintial value.
oflagcontrol flag.
modeopen mode.

◆ Semaphore() [3/3]

join::Semaphore::Semaphore ( const Semaphore & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ ~Semaphore()

Semaphore::~Semaphore ( )
noexcept

destroy instance.

Member Function Documentation

◆ operator=()

Semaphore & join::Semaphore::operator= ( const Semaphore & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ post()

void Semaphore::post ( )
noexcept

increments the internal counter and unblocks acquirers.

◆ timedWait()

template<class Rep , class Period >
bool join::Semaphore::timedWait ( std::chrono::duration< Rep, Period > timeout)
inline

tries to decrement the internal counter, blocking for up to a duration time.

Parameters
timeouttimeout.
Returns
true on success, false otherwise.

◆ tryWait()

bool Semaphore::tryWait ( )
noexcept

tries to decrement the internal counter without blocking.

Returns
true on success, false otherwise.

◆ value()

int Semaphore::value ( )
noexcept

get semaphore value.

Returns
-1 on error, semaphore value otherwise.

◆ wait()

void Semaphore::wait ( )
noexcept

decrements the internal counter or blocks until it can

Member Data Documentation

◆ _named_handle

sem_t* join::Semaphore::_named_handle

◆ _unnamed_handle

sem_t join::Semaphore::_unnamed_handle

The documentation for this class was generated from the following files: