Zth (libzth)
Loading...
Searching...
No Matches
zth::Semaphore Class Reference

Fiber-aware semaphore. More...

#include <sync.h>

Inheritance diagram for zth::Semaphore:
zth::Synchronizer< Size > zth::SynchronizerBase zth::RefCounted zth::UniqueID< SynchronizerBase > zth::NamedUniqueID< Named > zth::UniqueIDBase

Public Types

typedef unsigned int count_type
 
- Public Types inherited from zth::Synchronizer< Size >
typedef SynchronizerBase base
 
- Public Types inherited from zth::UniqueID< SynchronizerBase >
typedef NamedUniqueID base
 

Public Member Functions

 Semaphore (count_type init=0, cow_string const &name="Semaphore")
 
 Semaphore (count_type init, cow_string &&name)
 
virtual ~Semaphore () noexcept override=default
 
void acquire (count_type count=1)
 
void release (count_type count=1) noexcept
 
count_type value () const noexcept
 
- Public Member Functions inherited from zth::Synchronizer< Size >
 Synchronizer ()=default
 
 Synchronizer (cow_string const &name)
 
 Synchronizer (cow_string &&name)
 
virtual ~Synchronizer () noexcept override
 
- Public Member Functions inherited from zth::SynchronizerBase
virtual ~SynchronizerBase () noexcept override
 
- Public Member Functions inherited from zth::RefCounted
 RefCounted () noexcept
 
virtual ~RefCounted () noexcept
 
void used () noexcept
 
bool unused () noexcept
 
size_t refs () const noexcept
 
- Public Member Functions inherited from zth::UniqueID< SynchronizerBase >
 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 () noexcept override=default
 
void const * normptr () const noexcept
 
uint64_t id () const noexcept
 
- Public Member Functions inherited from zth::NamedUniqueID< Named >
virtual ~NamedUniqueID () noexcept override=default
 
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 noexcept override
 

Additional Inherited Members

- Static Public Member Functions inherited from zth::UniqueID< SynchronizerBase >
static uint64_t getID () noexcept
 
- Protected Types inherited from zth::Synchronizer< Size >
typedef base::queue_type queue_type
 
- Protected Types inherited from zth::SynchronizerBase
typedef List queue_type
 
- Protected Member Functions inherited from zth::Synchronizer< Size >
virtual queue_typequeue (size_t q) final
 
- Protected Member Functions inherited from zth::SynchronizerBase
 SynchronizerBase (cow_string const &name="Synchronizer")
 
 SynchronizerBase (cow_string &&name)
 
queue_type::iterator enqueue (Listable &item, size_t q=0) noexcept
 
void block (size_t q=0)
 
bool unblock (Fiber &f, size_t q=0, bool prio=false) noexcept
 Unblock the specific fiber.
 
ListableunblockFirst (size_t q=0, bool prio=false) noexcept
 
bool unblockAll (size_t q=0, bool prio=false) noexcept
 
virtual void wakeup (Listable &item, queue_type::user_type user, bool prio, size_t q) noexcept
 
bool blockUntil (Timestamp const &timeout, Timestamp const &now=Timestamp::now(), size_t q=0)
 Block, with timeout.
 
bool blockFor (TimeInterval const &timeout, Timestamp const &now=Timestamp::now(), size_t q=0)
 Block, with timeout.
 
- Protected Member Functions inherited from zth::RefCounted
virtual void cleanup () noexcept
 
- Protected Member Functions inherited from zth::UniqueID< SynchronizerBase >
virtual uint64_t id_ () const noexcept final
 
- Protected Member Functions inherited from zth::NamedUniqueID< Named >
 NamedUniqueID (char const *name=nullptr)
 
 NamedUniqueID (string const &name)
 
 NamedUniqueID (string &&name)
 
- Protected Member Functions inherited from zth::UniqueIDBase
virtual ~UniqueIDBase () noexcept=default
 

Detailed Description

Fiber-aware semaphore.

Definition at line 614 of file sync.h.

Member Typedef Documentation

◆ count_type

typedef unsigned int zth::Semaphore::count_type

Definition at line 617 of file sync.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

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

Definition at line 619 of file sync.h.

◆ Semaphore() [2/2]

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

Definition at line 626 of file sync.h.

◆ ~Semaphore()

virtual zth::Semaphore::~Semaphore ( )
overridevirtualdefaultnoexcept

Member Function Documentation

◆ acquire()

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

Definition at line 635 of file sync.h.

◆ release()

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

Definition at line 653 of file sync.h.

◆ value()

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

Definition at line 678 of file sync.h.


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