aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2023-08-25 09:45:21 +0300
committerbabenko <babenko@yandex-team.com>2023-08-25 09:58:30 +0300
commit2d3d5795145d4a0e1af689832d96daec93ae09c7 (patch)
tree171ae86a8c561178e80a6734672d0db1a4d95a5b
parent1f74f9e363b1517cf9797e88d21f05b828f3ae44 (diff)
downloadydb-2d3d5795145d4a0e1af689832d96daec93ae09c7.tar.gz
Simplify TAsyncSemaphore::AsyncAcquire
-rw-r--r--yt/yt/core/concurrency/async_semaphore.cpp9
-rw-r--r--yt/yt/core/concurrency/async_semaphore.h4
2 files changed, 4 insertions, 9 deletions
diff --git a/yt/yt/core/concurrency/async_semaphore.cpp b/yt/yt/core/concurrency/async_semaphore.cpp
index 98a2b11b2cd..b5555ed6e0d 100644
--- a/yt/yt/core/concurrency/async_semaphore.cpp
+++ b/yt/yt/core/concurrency/async_semaphore.cpp
@@ -25,7 +25,7 @@ void TAsyncSemaphore::SetTotal(i64 totalSlots)
Release(0);
}
-void TAsyncSemaphore::Release(i64 slots /* = 1 */)
+void TAsyncSemaphore::Release(i64 slots)
{
YT_VERIFY(slots >= 0);
@@ -68,7 +68,7 @@ void TAsyncSemaphore::Release(i64 slots /* = 1 */)
for (const auto& waiter : waitersToRelease) {
// NB: This may lead to a reentrant invocation of Release if the invoker discards the callback.
- waiter.Invoker->Invoke(BIND(waiter.Handler, Passed(TAsyncSemaphoreGuard(this, waiter.Slots))));
+ waiter.Handler(TAsyncSemaphoreGuard(this, waiter.Slots));
}
if (readyEventToSet) {
@@ -99,7 +99,6 @@ bool TAsyncSemaphore::TryAcquire(i64 slots /*= 1*/)
void TAsyncSemaphore::AsyncAcquire(
const TCallback<void(TAsyncSemaphoreGuard)>& handler,
- IInvokerPtr invoker,
i64 slots)
{
YT_VERIFY(slots >= 0);
@@ -108,9 +107,9 @@ void TAsyncSemaphore::AsyncAcquire(
if (FreeSlots_ >= slots) {
FreeSlots_ -= slots;
guard.Release();
- invoker->Invoke(BIND(handler, Passed(TAsyncSemaphoreGuard(this, slots))));
+ handler(TAsyncSemaphoreGuard(this, slots));
} else {
- Waiters_.push(TWaiter{handler, std::move(invoker), slots});
+ Waiters_.push(TWaiter{handler, slots});
}
}
diff --git a/yt/yt/core/concurrency/async_semaphore.h b/yt/yt/core/concurrency/async_semaphore.h
index 3f780093a71..7f6d646b134 100644
--- a/yt/yt/core/concurrency/async_semaphore.h
+++ b/yt/yt/core/concurrency/async_semaphore.h
@@ -72,10 +72,8 @@ public:
//! Runs #handler when a given number of slots becomes available.
//! These slots are immediately captured by TAsyncSemaphoreGuard instance passed to #handler.
- // XXX(babenko): passing invoker is a temporary workaround until YT-3801 is fixed
void AsyncAcquire(
const TCallback<void(TAsyncSemaphoreGuard)>& handler,
- IInvokerPtr invoker,
i64 slots = 1);
//! Returns |true| iff at least one slot is free.
@@ -107,12 +105,10 @@ private:
struct TWaiter
{
TCallback<void(TAsyncSemaphoreGuard)> Handler;
- IInvokerPtr Invoker;
i64 Slots;
};
std::queue<TWaiter> Waiters_;
-
};
DEFINE_REFCOUNTED_TYPE(TAsyncSemaphore)