From aabbdc34ac233b18e91849f7fa74d05ffe3edf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Fri, 10 Jul 2020 12:09:17 +0300 Subject: [PATCH] reader_concurrency_semaphore: add initial_resources() To allow tests to reliably calculate the amount of resources they need to consume in order to effectively reduce the resources of the semaphore to a desired amount. Using `available_resources()` is not reliable as it doesn't factor in resources that are consumed at the moment but will be returned later. This will also benefit debugging coredumps where we will now be able to tell how much resources the semaphore was created with and this calculate the amount of memory and count currently used. --- reader_concurrency_semaphore.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/reader_concurrency_semaphore.hh b/reader_concurrency_semaphore.hh index 89a6fea969..b4e34f2ae6 100644 --- a/reader_concurrency_semaphore.hh +++ b/reader_concurrency_semaphore.hh @@ -105,6 +105,7 @@ private: }; private: + const resources _initial_resources; resources _resources; expiring_fifo _wait_list; @@ -135,7 +136,8 @@ public: sstring name, size_t max_queue_length = std::numeric_limits::max(), std::function prethrow_action = nullptr) - : _resources(count, memory) + : _initial_resources(count, memory) + , _resources(count, memory) , _wait_list(expiry_handler(name)) , _name(std::move(name)) , _max_queue_length(max_queue_length) @@ -193,6 +195,10 @@ public: reader_permit make_permit(); + const resources initial_resources() const { + return _initial_resources; + } + const resources available_resources() const { return _resources; }