6#ifndef BITCOIN_SEMAPHORE_GRANT_H
7#define BITCOIN_SEMAPHORE_GRANT_H
12template <std::ptrdiff_t LeastMaxValue = std::counting_semaphore<>::max()>
16 std::counting_semaphore<LeastMaxValue>*
sem;
40 if (!fHaveGrant && sem->try_acquire()) {
54 fHaveGrant = other.fHaveGrant;
55 other.fHaveGrant =
false;
63 fHaveGrant = other.fHaveGrant;
64 other.fHaveGrant =
false;
71 explicit CountingSemaphoreGrant(std::counting_semaphore<LeastMaxValue>& sema,
bool fTry =
false) noexcept : sem(&sema), fHaveGrant(false)
85 explicit operator bool() const noexcept
RAII-style semaphore lock.
CountingSemaphoreGrant() noexcept
CountingSemaphoreGrant(CountingSemaphoreGrant &&other) noexcept
CountingSemaphoreGrant & operator=(CountingSemaphoreGrant &&other) noexcept
std::counting_semaphore< LeastMaxValue > * sem
bool TryAcquire() noexcept
~CountingSemaphoreGrant()
CountingSemaphoreGrant(std::counting_semaphore< LeastMaxValue > &sema, bool fTry=false) noexcept
CountingSemaphoreGrant(const CountingSemaphoreGrant &)=delete
CountingSemaphoreGrant & operator=(const CountingSemaphoreGrant &)=delete