29 #ifndef _GLIBCXX_SEMAPHORE
30 #define _GLIBCXX_SEMAPHORE 1
32 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
38 #define __glibcxx_want_semaphore
41 #ifdef __cpp_lib_semaphore
44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 template<ptrdiff_t __least_max_value = _Semaphore_impl<2>::_S_max>
49 class counting_semaphore
51 static_assert(__least_max_value >= 0);
53 _Semaphore_impl<__least_max_value> _M_sem;
57 counting_semaphore(ptrdiff_t __desired) noexcept
59 { __glibcxx_assert(__desired >= 0 && __desired <=
max()); }
61 ~counting_semaphore() =
default;
63 counting_semaphore(
const counting_semaphore&) =
delete;
64 counting_semaphore& operator=(
const counting_semaphore&) =
delete;
66 static constexpr ptrdiff_t
68 {
return __least_max_value; }
71 release(ptrdiff_t __update = 1) noexcept
73 [[maybe_unused]] ptrdiff_t __old = _M_sem._M_release(__update);
74 __glibcxx_assert(__update >= 0 && __update <=
max() - __old);
78 acquire() noexcept(noexcept(_M_sem._M_acquire()))
79 { _M_sem._M_acquire(); }
82 try_acquire() noexcept(noexcept(_M_sem._M_try_acquire()))
83 {
return _M_sem._M_try_acquire(); }
85 template<
typename _Rep,
typename _Period>
88 {
return _M_sem._M_try_acquire_for(__rtime); }
90 template<
typename _Clock,
typename _Dur>
93 {
return _M_sem._M_try_acquire_until(__atime); }
100 using binary_semaphore = std::counting_semaphore<1>;
102 _GLIBCXX_END_NAMESPACE_VERSION
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock