Beispiel #1
0
VOID _IncreaseBlockReference(PCACHE_POOL CachePool, PCACHE_BLOCK pBlock)
{
    pBlock->ReferenceCount++;
    // Move it to the head of list
    if (pBlock->Protected == TRUE)
    {
        ListMoveToHead(&CachePool->HotList, pBlock);
    }
    else
    {
        ListMoveToHead(&CachePool->ColdList, pBlock);
    }
}
Beispiel #2
0
VOID _IncreaseBlockReference(PCACHE_POOL CachePool, PCACHE_BLOCK pBlock)
{
    PCACHE_BLOCK    _pBlock, Top;

    if (pBlock->Protected == TRUE)
    {
        ListMoveToHead(&CachePool->ProtectedList, pBlock);
    }
    else
    {
        ListDelete(&CachePool->ProbationaryList, pBlock);
        CachePool->Probationary_bpt_root = Delete(CachePool->Probationary_bpt_root, pBlock->Index, FALSE);
        // Protected is Full
        if (CachePool->ProtectedList.Size == CachePool->ProtectedSize)
        {
            // Remove one from Protected
            _pBlock = ListRemoveTail(&CachePool->ProtectedList);
            CachePool->Protected_bpt_root = Delete(CachePool->Protected_bpt_root, _pBlock->Index, FALSE);
            // Move to Probationary
            // Probationary Obviously Not Full for We just Remove one from it
            _pBlock->Protected = FALSE;
            ListInsertToHead(&CachePool->ProbationaryList, _pBlock);
            CachePool->Probationary_bpt_root = Insert(CachePool->Probationary_bpt_root, _pBlock->Index, _pBlock);
        }
        // Add to Protected
        pBlock->Protected = TRUE;
        ListInsertToHead(&CachePool->ProtectedList, pBlock);
        CachePool->Protected_bpt_root = Insert(CachePool->Protected_bpt_root, pBlock->Index, pBlock);
    }
}
Beispiel #3
0
int ListFindIndexOf(struct List **hist, char *pszValue, int val)
{
  int index=0;
  char *compval = NULL;
  struct List *temp = *hist;

  if(*hist && pszValue) {
    ListMoveToHead(hist);
    compval = val ? (*hist)->name : (*hist)->command;

    while((*hist)->next) {
      ++index;
      if(!stricmp(compval, pszValue))
        return index;
      ListMoveNext(hist, 1);
      compval = val ? (*hist)->name : (*hist)->command;
    }

    ++index;
    if(!stricmp(compval, pszValue))
      return index;

    *hist = temp;
    return 0;
  }

  *hist = temp;
  return -1;
}
Beispiel #4
0
struct List *ListRemoveAll(struct List **hist, int *count)
{
  if(*hist) {
    ListMoveToHead(hist);
    while(*hist) {
      ListRemoveEntry(hist, count);
    }
  }
  return *hist;
}
Beispiel #5
0
/**
 * Find a Non-Modified Cache Block to Replace when Pool is Full
 * (Find From Probationary Segment)
 */
PCACHE_BLOCK _FindBlockToReplace(PCACHE_POOL CachePool, LONGLONG Index, PVOID Data, BOOLEAN Modified)
{
    PCACHE_BLOCK    pBlock;

    pBlock = CachePool->ProbationaryList.Tail;
#ifdef WRITE_BACK_ENABLE
    // Backward find first Non-Modified in Probationary List
    while (pBlock && pBlock->Modified == TRUE)
        pBlock = pBlock->Prior;
#endif

    if (pBlock)
    {
        CachePool->Probationary_bpt_root = Delete(CachePool->Probationary_bpt_root, pBlock->Index, FALSE);
        pBlock->Modified = Modified;
        pBlock->Index = Index;
        pBlock->Protected = FALSE;
        StoragePoolWrite (
            &CachePool->Storage,
            pBlock->StorageIndex, 0,
            Data,
            BLOCK_SIZE
        );
        ListMoveToHead(&CachePool->ProbationaryList, pBlock);
        CachePool->Probationary_bpt_root = Insert(CachePool->Probationary_bpt_root, Index, pBlock);
    }
#ifdef WRITE_BACK_ENABLE
    else
    {
        // There always exist Non-Modified Blocks, When Probationary is Full
        ASSERT(CachePool->ProbationaryList.Size < CachePool->ProbationarySize);
        // Cold List not full
        pBlock = _AddNewBlockToPool(CachePool, Index, Data, Modified);
        ASSERT(pBlock);
    }
#endif

    return pBlock;
}
Beispiel #6
0
BOOL ListMoveToEntry(struct List **hist, char *pszValue, int val)
{
  char *compval = NULL;

  if(*hist && pszValue) {
    ListMoveToHead(hist);
    compval = val ? (*hist)->name : (*hist)->command;

    while((*hist)->next) {
      if(!_stricmp(compval, pszValue))
        return TRUE;
      ListMoveNext(hist, 1);
      compval = val ? (*hist)->name : (*hist)->command;
    }

    if(!_stricmp(compval, pszValue))
      return TRUE;

    return FALSE;
  }

  return FALSE;
}