• 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列表。

    使用:
  • 相关阅读:
    window下启动tomcat输出日志乱码
    Mybatis
    JAVA-Stream
    记录-linux安装supervisor来监控elasticsearch
    草稿
    定时任务
    阿里云linux6.9 64位安装mysql5.7.23记录
    归并排序
    快速排序
    HTML DOM
  • 原文地址:https://www.cnblogs.com/mingziday/p/2360546.html
Copyright © 2020-2023  润新知