Skip to content

Commit

Permalink
stock/BasicStock: move code from GetCreate() to GetCanceled()
Browse files Browse the repository at this point in the history
GetCanceled() can be called even if the stock is full.
  • Loading branch information
MaxKellermann committed Oct 17, 2023
1 parent 7e699a5 commit dcac2e1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/stock/BasicStock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,25 @@ BasicStock::GetIdle(StockRequest &request,
return true;
}

void
BasicStock::GetCreate(StockRequest request,
StockGetHandler &get_handler,
CancellablePointer &cancel_ptr) noexcept
bool
BasicStock::GetCanceled(StockGetHandler &get_handler,
CancellablePointer &cancel_ptr) noexcept
{
for (auto &c : create) {
if (c.IsDetached()) {
c.Attach(get_handler, cancel_ptr);
return;
return true;
}
}

return false;
}

void
BasicStock::GetCreate(StockRequest request,
StockGetHandler &get_handler,
CancellablePointer &cancel_ptr) noexcept
{
auto *c = new Create(*this,
cls.ShouldContinueOnCancel(request.get()),
get_handler, cancel_ptr);
Expand Down
9 changes: 9 additions & 0 deletions src/stock/BasicStock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ public:
bool GetIdle(StockRequest &request,
StockGetHandler &handler) noexcept;

/**
* Attach the handler to a canceled create request.
*
* @return true on success, false if no canceled create
* requests exists
*/
bool GetCanceled(StockGetHandler &get_handler,
CancellablePointer &cancel_ptr) noexcept;

void GetCreate(StockRequest request,
StockGetHandler &get_handler,
CancellablePointer &cancel_ptr) noexcept;
Expand Down
11 changes: 7 additions & 4 deletions src/stock/Stock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ Stock::RetryWaiting() noexcept
--i) {
auto &w = waiting.pop_front();

GetCreate(std::move(w.request),
w.handler,
w.cancel_ptr);
if (!GetCanceled(w.handler, w.cancel_ptr))
GetCreate(std::move(w.request),
w.handler,
w.cancel_ptr);

w.Destroy();
}
}
Expand Down Expand Up @@ -157,7 +159,8 @@ Stock::Get(StockRequest request,
{
may_clear = false;

if (GetIdle(request, get_handler))
if (GetIdle(request, get_handler) ||
GetCanceled(get_handler, cancel_ptr))
return;

if (IsFull()) {
Expand Down

0 comments on commit dcac2e1

Please sign in to comment.