tensorflow/c/experimental/filesystem/plugins/gcs/ram_file_block_cache.cc
/// Move the block to the front of the LRU list if it isn't already there.
Move the block to the front of the LRU list if it isn't already there.
Move the block to the front of the LRU list if it isn ' t already there .
void RamFileBlockCache::UpdateLRU(const Key& key,
                                  const std::shared_ptr<Block>& block,
                                  TF_Status* status) {
  absl::MutexLock lock(&mu_);
  if (block->timestamp == 0) {
    return TF_SetStatus(status, TF_OK, "");
  }
  if (block->lru_iterator != lru_list_.begin()) {
    lru_list_.erase(block->lru_iterator);
    lru_list_.push_front(key);
    block->lru_iterator = lru_list_.begin();
  }
  if (block->data.size() < block_size_) {
    Key fmax = std::make_pair(key.first, std::numeric_limits<size_t>::max());
    auto fcmp = block_map_.upper_bound(fmax);
    if (fcmp != block_map_.begin() && key < (--fcmp)->first) {
      return TF_SetStatus(status, TF_INTERNAL,
                          "Block cache contents are inconsistent.");
    }
  }
  Trim();
  return TF_SetStatus(status, TF_OK, "");
}
void RamFileBlockCache :: UpdateLRU ( const Key & key , const std :: shared_ptr < Block > & block , TF_Status * status ) { absl :: MutexLock lock ( & mu_ ) ; if ( block -> timestamp == 0 ) { return TF_SetStatus ( status , TF_OK , " " ) ; } if ( block -> lru_iterator != lru_list_ . begin ( ) ) { lru_list_ . erase ( block -> lru_iterator ) ; lru_list_ . push_front ( key ) ; block -> lru_iterator = lru_list_ . begin ( ) ; } if ( block -> data . size ( ) < block_size_ ) { Key fmax = std :: make_pair ( key . first , std :: numeric_limits < size_t > :: max ( ) ) ; auto fcmp = block_map_ . upper_bound ( fmax ) ; if ( fcmp != block_map_ . begin ( ) && key < ( -- fcmp ) -> first ) { return TF_SetStatus ( status , TF_INTERNAL , " " ) ; } } Trim ( ) ; return TF_SetStatus ( status , TF_OK , " " ) ; }
Move the block to the front of the LRU list if it isn't already there.
Move the block to the front of the LRU list if it isn ' t already there .
// The block was evicted from another thread. Allow it to remain evicted. // Check for inconsistent state. If there is a block later in the same file // in the cache, and our current block is not block size, this likely means // we have inconsistent state within the cache. Note: it's possible some // incomplete reads may still go undetected.