@@ -1219,26 +1219,39 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
12191219  //  Keep searching for a candidate until we were able to evict it
12201220  //  or until the search limit has been exhausted
12211221  unsigned  int  searchTries = 0 ;
1222-   auto  itr = mmContainer.getEvictionIterator ();
12231222  while  ((config_.evictionSearchTries  == 0  ||
1224-           config_.evictionSearchTries  > searchTries) &&
1225-          itr) {
1223+           config_.evictionSearchTries  > searchTries)) {
12261224    ++searchTries;
12271225
1228-     Item* toRecycle = itr.get ();
1226+     Item* toRecycle = nullptr ;
1227+     Item* candidate = nullptr ;
12291228
1230-     Item*  candidate = 
1231-         toRecycle-> isChainedItem () 
1232-             ? &toRecycle-> asChainedItem (). getParentItem (compressor_) 
1233-             : toRecycle ;
1229+     mmContainer. withEvictionIterator ([ this , & candidate, &toRecycle, &searchTries]( auto  &&itr){ 
1230+       while  ((config_. evictionSearchTries  ==  0  || 
1231+           config_. evictionSearchTries  > searchTries) && itr) { 
1232+         ++searchTries ;
12341233
1235-     //  make sure no other thead is evicting the item
1236-     if  (candidate->getRefCount () != 0  || !candidate->markMoving ()) {
1237-       ++itr;
1234+         auto  *toRecycle_ = itr.get ();
1235+         auto  *candidate_ = toRecycle_->isChainedItem ()
1236+             ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
1237+             : toRecycle_;
1238+ 
1239+         //  make sure no other thead is evicting the item
1240+         if  (candidate_->getRefCount () == 0  && candidate_->markMoving ()) {
1241+           toRecycle = toRecycle_;
1242+           candidate = candidate_;
1243+           return ;
1244+         }
1245+ 
1246+         ++itr;
1247+       }
1248+     });
1249+ 
1250+     if  (!toRecycle)
12381251      continue ;
1239-     }
12401252
1241-     itr.destroy ();
1253+     XDCHECK (toRecycle);
1254+     XDCHECK (candidate);
12421255
12431256    //  for chained items, the ownership of the parent can change. We try to
12441257    //  evict what we think as parent and see if the eviction of parent
@@ -1299,8 +1312,6 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
12991312        return  toRecycle;
13001313      }
13011314    }
1302- 
1303-     itr.resetToBegin ();
13041315  }
13051316  return  nullptr ;
13061317}
0 commit comments