25#ifndef ORIGINAL_SEMAPHORES_H
26#define ORIGINAL_SEMAPHORES_H
47 template<u_
integer MAX_CNT = 1>
181 template<u_
integer MAX_CNT>
201template<original::u_
integer MAX_CNT>
204template<original::u_
integer MAX_CNT>
212template<original::u_
integer MAX_CNT>
216 this->condition_.wait(this->mutex_, [
this]{
217 return this->count_ > 0;
221 this->condition_.notify();
224template<original::u_
integer MAX_CNT>
228 if (this->count_ == 0) {
233 this->condition_.notify();
237template<original::u_
integer MAX_CNT>
243 return this->count_ > 0;
250 this->condition_.notify();
255template<original::u_
integer MAX_CNT>
262 this->condition_.wait(this->mutex_, [
this,
increase] {
267 this->condition_.notifySome(
increase);
270template<original::u_
integer MAX_CNT>
279 this->condition_.notifySome(
increase);
283template<original::u_
integer MAX_CNT>
296 this->condition_.notifySome(
increase);
301template<original::u_
integer MAX_CNT>
303 return this->releaseFor(1,
timeout);
312 this->condition_.wait(this->mutex_, [
this]{
313 return this->count_ > 0;
320 if (this->count_ == 0) {
329 const bool success = this->condition_.waitFor(this->mutex_,
timeout, [
this]{
330 return this->count_ > 0;
343 this->condition_.notifySome(
increase);
346template<original::u_
integer MAX_CNT>
351template<original::u_
integer MAX_CNT>
353 this->semaphore_.release();
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
POSIX condition variable implementation.
Definition condition.h:129
POSIX thread mutex implementation.
Definition mutex.h:153
static std::string formatString(const TYPE &t)
Universal value-to-string conversion with type-specific formatting.
Definition printable.h:339
RAII wrapper for automatic semaphore management.
Definition semaphores.h:182
~semaphoreGuard()
Destructor that releases the semaphore.
Definition semaphores.h:352
semaphoreGuard(semaphore< MAX_CNT > &sem)
Constructs a guard and acquires the semaphore.
Definition semaphores.h:347
Counting semaphore with maximum count constraint.
Definition semaphores.h:48
void release(u_integer increase=1)
Releases resources (increments count)
Definition semaphores.h:256
void acquire()
Acquires one resource (decrements count)
Definition semaphores.h:213
bool acquireFor(time::duration timeout)
Attempts to acquire one resource with timeout.
Definition semaphores.h:238
semaphore(u_integer init_count)
Constructs a semaphore with specified initial count.
Definition semaphores.h:205
bool releaseFor(u_integer increase, time::duration timeout)
Attempts to release resources with timeout.
Definition semaphores.h:284
semaphore()
Constructs a semaphore with maximum count.
Definition semaphores.h:202
bool tryRelease(u_integer increase=1)
Attempts to release resources without blocking.
Definition semaphores.h:271
bool tryAcquire()
Attempts to acquire one resource without blocking.
Definition semaphores.h:225
bool releaseFor(const time::duration &timeout)
Attempts to release one resource with timeout.
Definition semaphores.h:302
Represents a time duration with nanosecond precision.
Definition zeit.h:134
RAII wrapper for single mutex locking.
Definition mutex.h:216
Exception for invalid parameter values.
Definition error.h:219
Condition variable implementation for thread synchronization.
Platform-independent type definitions and compiler/platform detection.
Custom exception classes and callback validation utilities.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
Cross-platform mutex and lock management utilities.
Main namespace for the project Original.
Definition algorithms.h:21