zoukankan      html  css  js  c++  java
  • Linux下链表常用实现方式

    struct _inode_table {
            pthread_mutex_t lock;
            size_t hashsize; 
            char *name; 
            struct list_head lru; 
            size_t lru_size;
    };
    struct _inode {
            inode_table_t *table; 
            uuid_t gfid;
            gf_lock_t lock;
            struct list_head list;
    };

    struct list_head {
        struct list_head *next;
        struct list_head *prev;
    };

      
    //初始化,头和尾都指向自己
    #define INIT_LIST_HEAD(head) do {            \
            (head)->next = (head)->prev = head;    \
        } while (0)
    //添加到双向列表
    static inline void list_add (struct list_head *new, struct list_head *head)
    {
        new->prev = head;
        new->next = head->next;
        new->prev->next = new;
        new->next->prev = new;
    }
    //初始化函数
    _inode_table_t*
     inode_table_new {
     inode_table_t *new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t);
     INIT_LIST_HEAD (&new->lru);
    }
    //初始化函数,
    inode_t *
    inode_new (inode_table_t *table)
    {
    inode_t *newi = NULL;
    newi->table = table;
    INIT_LIST_HEAD (&newi->list);
    list_add (&newi->list, &table->lru);
    table->lru_size++;
    }
    每生产一个inode,inode自己维护inode->list,并把inode->list添加到table->lru里面去,由table维护整个inode列表。

    使用:
  • 相关阅读:
    Django 点滴
    Django 用 userena 做用户注册验证登陆
    screen 基础用法(转)
    yum 常用命令
    利用 awk 将当前的链接按端口汇总倒排序
    Django 的逆向解析url(转)
    Ubuntu 安装 setuptools
    支付宝 python alipay 集成(转)
    linux 下批量在多文件中替换字符串
    springmvc进阶
  • 原文地址:https://www.cnblogs.com/mingziday/p/2360546.html
Copyright © 2011-2022 走看看