summaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src')
-rw-r--r--vespalib/src/tests/shared_operation_throttler/shared_operation_throttler_test.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp8
-rw-r--r--vespalib/src/vespa/vespalib/util/shared_operation_throttler.h4
3 files changed, 12 insertions, 10 deletions
diff --git a/vespalib/src/tests/shared_operation_throttler/shared_operation_throttler_test.cpp b/vespalib/src/tests/shared_operation_throttler/shared_operation_throttler_test.cpp
index eefc0ca72c0..d6946905236 100644
--- a/vespalib/src/tests/shared_operation_throttler/shared_operation_throttler_test.cpp
+++ b/vespalib/src/tests/shared_operation_throttler/shared_operation_throttler_test.cpp
@@ -4,6 +4,8 @@
#include <vespa/vespalib/util/barrier.h>
#include <thread>
+using vespalib::steady_clock;
+
namespace vespalib {
using ThrottleToken = SharedOperationThrottler::Token;
@@ -47,7 +49,7 @@ TEST_F("blocking acquire returns immediately if slot available", DynamicThrottle
auto token = f1._throttler->blocking_acquire_one();
EXPECT_TRUE(token.valid());
token.reset();
- token = f1._throttler->blocking_acquire_one(600s); // Should never block.
+ token = f1._throttler->blocking_acquire_one(steady_clock::now() + 600s); // Should never block.
EXPECT_TRUE(token.valid());
}
@@ -70,11 +72,11 @@ TEST_F("blocking call woken up if throttle slot available", DynamicThrottleFixtu
TEST_F("time-bounded blocking acquire waits for timeout", DynamicThrottleFixture()) {
auto window_filling_token = f1._throttler->try_acquire_one();
- auto before = std::chrono::steady_clock::now();
+ auto before = steady_clock::now();
// Will block for at least 1ms. Since no window slot will be available by that time,
// an invalid token should be returned.
- auto token = f1._throttler->blocking_acquire_one(1ms);
- auto after = std::chrono::steady_clock::now();
+ auto token = f1._throttler->blocking_acquire_one(before + 1ms);
+ auto after = steady_clock::now();
EXPECT_TRUE((after - before) >= 1ms);
EXPECT_FALSE(token.valid());
}
diff --git a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp
index 6e273d1a7ea..478d8c1b9e9 100644
--- a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp
+++ b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp
@@ -24,7 +24,7 @@ public:
internal_ref_count_increase();
return Token(this, TokenCtorTag{});
}
- Token blocking_acquire_one(vespalib::duration) noexcept override {
+ Token blocking_acquire_one(vespalib::steady_time) noexcept override {
internal_ref_count_increase();
return Token(this, TokenCtorTag{});
}
@@ -267,7 +267,7 @@ public:
~DynamicOperationThrottler() override;
Token blocking_acquire_one() noexcept override;
- Token blocking_acquire_one(vespalib::duration timeout) noexcept override;
+ Token blocking_acquire_one(vespalib::steady_time deadline) noexcept override;
Token try_acquire_one() noexcept override;
uint32_t current_window_size() const noexcept override;
uint32_t current_active_token_count() const noexcept override;
@@ -334,12 +334,12 @@ DynamicOperationThrottler::blocking_acquire_one() noexcept
}
DynamicOperationThrottler::Token
-DynamicOperationThrottler::blocking_acquire_one(vespalib::duration timeout) noexcept
+DynamicOperationThrottler::blocking_acquire_one(vespalib::steady_time deadline) noexcept
{
std::unique_lock lock(_mutex);
if (!has_spare_capacity_in_active_window()) {
++_waiting_threads;
- const bool accepted = _cond.wait_for(lock, timeout, [&] {
+ const bool accepted = _cond.wait_until(lock, deadline, [&] {
return has_spare_capacity_in_active_window();
});
--_waiting_threads;
diff --git a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.h b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.h
index b7913029c1e..95d6d361cb6 100644
--- a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.h
+++ b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.h
@@ -54,9 +54,9 @@ public:
// Acquire a valid throttling token, uninterruptedly blocking until one can be obtained.
[[nodiscard]] virtual Token blocking_acquire_one() noexcept = 0;
// Attempt to acquire a valid throttling token, waiting up to `timeout` for one to be
- // available. If the timeout is exceeded without any tokens becoming available, an
+ // available. If the deadline is reached without any tokens becoming available, an
// invalid token will be returned.
- [[nodiscard]] virtual Token blocking_acquire_one(vespalib::duration timeout) noexcept = 0;
+ [[nodiscard]] virtual Token blocking_acquire_one(vespalib::steady_time deadline) noexcept = 0;
// Attempt to acquire a valid throttling token if one is immediately available.
// An invalid token will be returned if none is available. Never blocks (other than
// when contending for the internal throttler mutex).