carb::tasking::SemaphoreWrapper

Defined in carb/tasking/TaskingUtils.h

class SemaphoreWrapper

Wrapper for a carb::tasking::Semaphore.

Note

SemaphoreWrapper can be used for Throttling tasks.

Public Functions

inline SemaphoreWrapper(unsigned value)

Constructs a new SemaphoreWrapper object.

Parameters

value – The initial value of the semaphore (i.e. how many times acquire() can be called without blocking).

inline SemaphoreWrapper(ITasking*, unsigned value)

Constructs a new SemaphoreWrapper object.

Note

Deprecated: ITasking no longer needed.

Parameters

value – The initial value of the semaphore (i.e. how many times acquire() can be called without blocking).

inline ~SemaphoreWrapper()

Destructor.

inline void release(unsigned count = 1)

Increases the value of the semaphore, potentially unblocking any threads waiting in acquire().

Parameters

count – The value to add to the Semaphore’s value. That is, the number of threads to either unblock while waiting in acquire(), or to allow to call acquire() without blocking.

inline void acquire()

Reduce the value of the Semaphore by one, potentially blocking if the count is already zero.

Note

Threads that are blocked by acquire() must be released by other threads calling release().

inline bool try_acquire()

Attempts to reduce the value of the Semaphore by one.

If the Semaphore’s value is zero, false is returned.

Returns

true if the count of the Semaphore was reduced by one; false if the count is already zero.

template<class Rep, class Period>
inline bool try_acquire_for(const std::chrono::duration<Rep, Period> &dur)

Attempts to reduce the value of the Semaphore by one, waiting until the duration expires if the value is zero.

Returns

true if the count of the Semaphore was reduced by one; false if the duration expires.

template<class Clock, class Duration>
inline bool try_acquire_until(const std::chrono::time_point<Clock, Duration> &tp)

Attempts to reduce the value of the Semaphore by one, waiting until the given time point is reached if the value is zero.

Returns

true if the count of the Semaphore was reduced by one; false if the time point is reached by the clock.

inline operator Semaphore*() const

Convertible to Semaphore*.

inline ITasking *getTasking() const

Returns the acquired ITasking interface that was used to construct this object.

Note

Deprecated: Use carb::getCachedInterface instead.