6 #ifndef BITCOIN_SEMAPHORE_GRANT_H 7 #define BITCOIN_SEMAPHORE_GRANT_H 12 template <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
93 #endif // BITCOIN_SEMAPHORE_GRANT_H std::counting_semaphore< LeastMaxValue > * sem
~CountingSemaphoreGrant()
CountingSemaphoreGrant() noexcept
CountingSemaphoreGrant(std::counting_semaphore< LeastMaxValue > &sema, bool fTry=false) noexcept
CountingSemaphoreGrant(CountingSemaphoreGrant &&other) noexcept
RAII-style semaphore lock.
bool TryAcquire() noexcept
CountingSemaphoreGrant & operator=(CountingSemaphoreGrant &&other) noexcept