roo_threads
API Documentation for roo_threads
Loading...
Searching...
No Matches
semaphore_api.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "roo_time.h"
6
7namespace roo_threads {
8namespace doc {
9
10template <std::ptrdiff_t LeastMaxValue>
11/// @ingroup roo_threads_api_semaphore
13 public:
14 /// @brief Constructs semaphore with initial token count.
15 /// @param desired initial token count.
16 explicit counting_semaphore(std::ptrdiff_t desired) noexcept;
17
20
21 /// @brief Acquires a token, blocking until one is available.
22 void acquire() noexcept;
23
24 /// @brief Attempts to acquire a token without blocking.
25 /// @return true if a token was acquired.
26 bool try_acquire() noexcept;
27
28 /// @brief Attempts to acquire a token for a bounded duration.
29 /// @param duration relative timeout duration.
30 /// @return true if a token was acquired.
31 bool try_acquire_for(const roo_time::Duration& duration) noexcept;
32
33 /// @brief Attempts to acquire a token until the given deadline.
34 /// @param when absolute timeout point.
35 /// @return true if a token was acquired.
36 bool try_acquire_until(const roo_time::Uptime& when) noexcept;
37
38 /// @brief Releases one token.
39 void release() noexcept;
40};
41
42/// @ingroup roo_threads_api_semaphore
43/// @brief Semaphore with maximum count of one.
45
46} // namespace doc
47} // namespace roo_threads
counting_semaphore(std::ptrdiff_t desired) noexcept
Constructs semaphore with initial token count.
void release() noexcept
Releases one token.
bool try_acquire_for(const roo_time::Duration &duration) noexcept
Attempts to acquire a token for a bounded duration.
bool try_acquire() noexcept
Attempts to acquire a token without blocking.
counting_semaphore & operator=(const counting_semaphore &)=delete
void acquire() noexcept
Acquires a token, blocking until one is available.
bool try_acquire_until(const roo_time::Uptime &when) noexcept
Attempts to acquire a token until the given deadline.
counting_semaphore(const counting_semaphore &)=delete