@@ -1682,28 +1682,8 @@ bool CodeStreamDecompress::fetchByTile(
16821682 startDecompressConsumer (std::min ((uint16_t )TFSingleton::num_threads (),
16831683 (uint16_t )((maxRowsAhead_ + 1 ) * cp_.t_grid_width_ )));
16841684
1685- // Back pressure: prevent the fetcher from scheduling more HTTP requests
1686- // when either (a) too many tiles are in-flight for decompression, or
1687- // (b) the fetcher is too far ahead of the consumer (swath-based release).
16881685 auto numTileCols = cp_.t_grid_width_ ;
1689- fetcher->setFetchThrottle ([this ]() {
1690- // Row-based: don't fetch tiles more than maxRowsAhead_ rows beyond
1691- // the last row released by the consumer.
1692- if (tileCompletion_)
1693- {
1694- int32_t lastCleared = tileCompletion_->getLastClearedTileY ();
1695- int32_t maxAllowed = lastCleared + maxRowsAhead_ + 2 ;
1696- if (maxFetchedTileRow_.load (std::memory_order_acquire) >= maxAllowed)
1697- return false ;
1698- }
1699- // In-flight: don't overwhelm the decompress pipeline
1700- uint16_t inFlight;
1701- {
1702- std::lock_guard<std::mutex> lock (decompressThrottleMutex_);
1703- inFlight = decompressInFlight_;
1704- }
1705- return decompressQueue_->size () + inFlight < maxDecompressInFlight_;
1706- });
1686+ installFetchThrottle (fetcher);
17071687
17081688 fetchByTileFutures_.push_back (fetcher->fetchTiles (
17091689 cp_.tlmMarkers_ ->getTileParts (), slated, nullptr ,
@@ -2053,6 +2033,28 @@ std::vector<std::pair<uint16_t, std::shared_ptr<TPFetchSeq>>>
20532033 return prefetchedTiles;
20542034}
20552035
2036+ void CodeStreamDecompress::installFetchThrottle (IFetcher* fetcher)
2037+ {
2038+ fetcher->setFetchThrottle ([this ]() {
2039+ // Row-based: don't fetch tiles more than maxRowsAhead_ rows beyond
2040+ // the last row released by the consumer.
2041+ if (tileCompletion_)
2042+ {
2043+ int32_t lastCleared = tileCompletion_->getLastClearedTileY ();
2044+ int32_t maxAllowed = lastCleared + maxRowsAhead_ + 2 ;
2045+ if (maxFetchedTileRow_.load (std::memory_order_acquire) >= maxAllowed)
2046+ return false ;
2047+ }
2048+ // In-flight: don't overwhelm the decompress pipeline
2049+ uint16_t inFlight;
2050+ {
2051+ std::lock_guard<std::mutex> lock (decompressThrottleMutex_);
2052+ inFlight = decompressInFlight_;
2053+ }
2054+ return decompressQueue_->size () + inFlight < maxDecompressInFlight_;
2055+ });
2056+ }
2057+
20562058bool CodeStreamDecompress::fetchByTileSelective (
20572059 std::set<uint16_t >& slated, Rect32 unreducedImageBounds,
20582060 std::function<std::function<void ()>(ITileProcessor*)> postGenerator)
@@ -2092,9 +2094,6 @@ bool CodeStreamDecompress::fetchByTileSelective(
20922094 auto phase1Future = phase1Promise.get_future ();
20932095 auto remainingTiles = std::make_shared<std::atomic<size_t >>(slated.size ());
20942096
2095- // Save slated tiles before Phase 1 fetch (fetchTiles moves the set)
2096- auto slatedTiles = slated;
2097-
20982097 // Phase 1 fetch: get tile-part headers
20992098 fetcher->fetchTiles (headerTileParts, slated, nullptr ,
21002099 [&headerResults, &headerMutex, &remainingTiles,
@@ -2149,7 +2148,7 @@ bool CodeStreamDecompress::fetchByTileSelective(
21492148 selectiveTileParts_.resize (allTileParts.size ());
21502149 auto selectiveFetchTiles = std::make_shared<std::set<uint16_t >>();
21512150
2152- for (auto tileIndex : slatedTiles )
2151+ for (auto tileIndex : slated )
21532152 {
21542153 auto it = headerResults->find (tileIndex);
21552154 if (it == headerResults->end ())
@@ -2196,21 +2195,7 @@ bool CodeStreamDecompress::fetchByTileSelective(
21962195
21972196 if (!selectiveFetchTiles->empty ())
21982197 {
2199- fetcher->setFetchThrottle ([this ]() {
2200- if (tileCompletion_)
2201- {
2202- int32_t lastCleared = tileCompletion_->getLastClearedTileY ();
2203- int32_t maxAllowed = lastCleared + maxRowsAhead_ + 2 ;
2204- if (maxFetchedTileRow_.load (std::memory_order_acquire) >= maxAllowed)
2205- return false ;
2206- }
2207- uint16_t inFlight;
2208- {
2209- std::lock_guard<std::mutex> lock (decompressThrottleMutex_);
2210- inFlight = decompressInFlight_;
2211- }
2212- return decompressQueue_->size () + inFlight < maxDecompressInFlight_;
2213- });
2198+ installFetchThrottle (fetcher);
22142199
22152200 fetchByTileFutures_.push_back (fetcher->fetchTiles (
22162201 selectiveTileParts_, *selectiveFetchTiles, nullptr ,
0 commit comments