⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lrulist.c

📁 一种用于编译时头文件的缓存处理缓存源代码,使用起来就像C/C++编译器的缓存预处理器,简化该功能相应的环境改变时对内核的影响。
💻 C
字号:
/********************************************************************
	created:	2008/01/23
	filename: 	lrulist.c
	author:		Lichuang
                
	purpose:    
*********************************************************************/

#include "lock.h"
#include "lrulist.h"
#include "node.h"

void linktolrulisthead(int index, ccache_t* cache)
{
    if (-1 == cache->lrufirst && -1 == cache->lrulast)
    {
        cache->lrufirst = cache->lrulast = index;
        return;
    }

    if (index == cache->lrufirst)
    {
        return;
    }

    node_t* node = NODE(cache, index), *tmp;

    if (index == cache->lrulast)
    {
        cache->lrulast = node->lruprev;
    }

    int lrunext = node->lrunext, lruprev = node->lruprev;
    if (-1 != lrunext)
    {
        tmp = NODE(cache, lrunext);
        tmp->lruprev = lruprev;
    }
    if (-1 != lruprev)
    {
        tmp = NODE(cache, lruprev);
        tmp->lrunext = lrunext;
    }

    node->lrunext = cache->lrufirst;
    node->lruprev = -1;
    if (-1 != cache->lrufirst)
    {
        tmp = NODE(cache, cache->lrufirst);
        tmp->lruprev = index;
    }
    cache->lrufirst = index;
}

int  freefromlrulist(int index, ccache_t* cache)
{
    node_t* node = NODE(cache, index), *tmp;
    int lrunext = node->lrunext, lruprev = node->lruprev;
    if (0 <= lrunext)
    {
        tmp = NODE(cache, lrunext);
        tmp->lruprev = lruprev;
    }
    if (0 <= lruprev)
    {
        tmp = NODE(cache, lruprev);
        tmp->lrunext = lrunext;
    }

    if (index == cache->lrufirst)
    {
        cache->lrufirst = lrunext;
    }
    if (index == cache->lrulast)
    {
        cache->lrulast = lruprev; 
    }

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -