zoukankan      html  css  js  c++  java
  • linux 内核 中链表list

    这个结构从list.h 移到了types.h, 可见内核对循环链表的重视

    include/linux/types.h中定义

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

    include/linux/list.h 中的宏

    初始化 一个叫name的链表节点

    #define LIST_HEAD_INIT(name) { &(name), &(name) }

    #define LIST_HEAD(name)
            struct list_head name = LIST_HEAD_INIT(name)

    eg:

    typdef struct  list_tag {

      struct list_head _list;

      int element;

      int other;

    } xxx_list_t;

    int main( void )

    {

      xxx_list_t l = {

        ._list = LIST_HEAD_INIT( l._list ),

        .element = 1,

        .other = 2,

      };

    }

     #define INIT_LIST_HEAD(ptr) do {
     (ptr)->next = (ptr); (ptr)->prev = (ptr);
     }

    变成了

     static inline void INIT_LIST_HEAD(struct list_head *list)
     {  
       list->next = list;
       list->prev = list;
     }

    不知还在哪里使用:

     #define LIST_HEAD(name)  
              struct list_head name = LIST_HEAD_INIT(name) 
    定义一个头, 没有其他数据部分
    xxxx_head
      next ------------------------>
      prev ------------------------>



    #define list_entry(ptr, type, member)  
             container_of(ptr, type, member)
    的作用是:

    返回指针
    ---->struct {

       ptr----> list
        ...
    }

    即根据ptr 是那个结构struct 中的 那个成员可以得出这个包含它的结构体指针
    这其中使用到了 typeof (根据一个变量返回一个 ‘类型‘)


  • 相关阅读:
    4月7日工作日志
    5月4日工作日志
    4月7日工作日志
    4月1日工作日志
    3月31日工作日志
    3月31日工作日志
    对元素绑定事件方法
    css实现垂直居中的各种方法
    纯css写一个switch开关
    弹性盒模型flex布局
  • 原文地址:https://www.cnblogs.com/kwingmei/p/3759965.html
Copyright © 2011-2022 走看看