diff --git a/include/cachinglayer/lrucache/DList.h b/include/cachinglayer/lrucache/DList.h index 8547a4a..048c9ac 100644 --- a/include/cachinglayer/lrucache/DList.h +++ b/include/cachinglayer/lrucache/DList.h @@ -106,6 +106,10 @@ class DList : public std::enable_shared_from_this { IsEmpty() const; // Reserve loading resource with timeout, called before loading a cell. + // When timeout > 0, the request will fail after the specified duration. + // When timeout == 0, the request will wait indefinitely (no timeout). + // Note: timeout=0 requests use time_point::max() as their deadline, which + // means they sort after all finite-deadline requests in the waiting queue. folly::SemiFuture ReserveLoadingResourceWithTimeout(const ResourceUsage& size, std::chrono::milliseconds timeout, OpContext* ctx = nullptr); diff --git a/src/cachinglayer/lrucache/DList.cpp b/src/cachinglayer/lrucache/DList.cpp index d0b5994..a3230e3 100644 --- a/src/cachinglayer/lrucache/DList.cpp +++ b/src/cachinglayer/lrucache/DList.cpp @@ -58,7 +58,8 @@ DList::ReserveLoadingResourceWithTimeout(const ResourceUsage& original_size, std // If immediate reservation fails, add to waiting queue std::unique_lock lock(list_mtx_); - auto deadline = std::chrono::steady_clock::now() + timeout; + auto deadline = + timeout.count() > 0 ? std::chrono::steady_clock::now() + timeout : std::chrono::steady_clock::time_point::max(); auto [promise, future] = folly::makePromiseContract(); uint64_t request_id = next_request_id_.fetch_add(1);