diff --git a/src/sync.h b/src/sync.h index 45298a0ee84..bef029427ab 100644 --- a/src/sync.h +++ b/src/sync.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -304,6 +305,7 @@ inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNE * * See https://en.wikipedia.org/wiki/Semaphore_(programming) */ +template ::max()> class CountingSemaphore { private: @@ -348,14 +350,15 @@ public: } }; -using BinarySemaphore = CountingSemaphore; -using Semaphore = CountingSemaphore; +using BinarySemaphore = CountingSemaphore<1>; +using Semaphore = CountingSemaphore<>; /** RAII-style semaphore lock */ +template ::max()> class CountingSemaphoreGrant { private: - CountingSemaphore* sem; + CountingSemaphore* sem; bool fHaveGrant; public: @@ -410,7 +413,7 @@ public: CountingSemaphoreGrant() noexcept : sem(nullptr), fHaveGrant(false) {} - explicit CountingSemaphoreGrant(CountingSemaphore& sema, bool fTry = false) noexcept : sem(&sema), fHaveGrant(false) + explicit CountingSemaphoreGrant(CountingSemaphore& sema, bool fTry = false) noexcept : sem(&sema), fHaveGrant(false) { if (fTry) { TryAcquire(); @@ -430,7 +433,7 @@ public: } }; -using BinarySemaphoreGrant = CountingSemaphoreGrant; -using SemaphoreGrant = CountingSemaphoreGrant; +using BinarySemaphoreGrant = CountingSemaphoreGrant<1>; +using SemaphoreGrant = CountingSemaphoreGrant<>; #endif // BITCOIN_SYNC_H