Zth (libzth)
zth::Semaphore Class Reference

Fiber-aware semaphore. More...

#include <sync.h>

Inheritance diagram for zth::Semaphore:
zth::Synchronizer zth::RefCounted zth::UniqueID< Synchronizer > zth::UniqueIDBase

Public Member Functions

 Semaphore (size_t init=0, cow_string const &name="Semaphore")
 
 Semaphore (size_t init, cow_string &&name)
 
virtual ~Semaphore () override=default
 
void acquire (size_t count=1)
 
void release (size_t count=1) noexcept
 
size_t value () const noexcept
 
- Public Member Functions inherited from zth::Synchronizer
 Synchronizer (cow_string const &name="Synchronizer")
 
 Synchronizer (cow_string &&name)
 
virtual ~Synchronizer () override
 
- Public Member Functions inherited from zth::RefCounted
 RefCounted () noexcept
 
virtual ~RefCounted ()=default
 
void used () noexcept
 
void unused ()
 
- Public Member Functions inherited from zth::UniqueID< Synchronizer >
 UniqueID (UniqueID const &)=delete
 
 UniqueID (UniqueID &&u) noexcept
 
 UniqueID (string const &name)
 
 UniqueID (string &&name)
 
 UniqueID (char const *name=nullptr)
 
UniqueIDoperator= (UniqueID const &)=delete
 
UniqueIDoperator= (UniqueID &&u) noexcept
 
virtual ~UniqueID ()=default
 
void const * normptr () const noexcept
 
uint64_t id () const noexcept
 
string const & name () const noexcept
 
void setName (string const &name)
 
void setName (char const *name)
 
void setName (string &&name)
 
virtual char const * id_str () const override
 

Additional Inherited Members

- Static Public Member Functions inherited from zth::UniqueID< Synchronizer >
static uint64_t getID () noexcept
 
- Protected Member Functions inherited from zth::Synchronizer
void block ()
 
bool unblock (Fiber &f) noexcept
 Unblock the specific fiber. More...
 
bool unblockFirst () noexcept
 
bool unblockAll () noexcept
 
bool block (Timestamp const &timeout, Timestamp const &now=Timestamp::now())
 Block, with timeout. More...
 
bool block (TimeInterval const &timeout, Timestamp const &now=Timestamp::now())
 Block, with timeout. More...
 
- Protected Member Functions inherited from zth::UniqueIDBase
virtual ~UniqueIDBase ()=default
 

Detailed Description

Fiber-aware semaphore.

Definition at line 390 of file sync.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

zth::Semaphore::Semaphore ( size_t  init = 0,
cow_string const &  name = "Semaphore" 
)
inlineexplicit

Definition at line 393 of file sync.h.

◆ Semaphore() [2/2]

zth::Semaphore::Semaphore ( size_t  init,
cow_string &&  name 
)
inline

Definition at line 399 of file sync.h.

◆ ~Semaphore()

virtual zth::Semaphore::~Semaphore ( )
overridevirtualdefault

Member Function Documentation

◆ acquire()

void zth::Semaphore::acquire ( size_t  count = 1)
inline

Definition at line 407 of file sync.h.

◆ release()

void zth::Semaphore::release ( size_t  count = 1)
inlinenoexcept

Definition at line 426 of file sync.h.

◆ value()

size_t zth::Semaphore::value ( ) const
inlinenoexcept

Definition at line 443 of file sync.h.


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