`
ackerman
  • 浏览: 72716 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

list.h from linux-2.4

 
阅读更多

#ifndef _LIST_H_
#define _LIST_H_

/* simple (cyclic) doubly linked list borrowed from linux 2.4 */

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

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

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

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

/*
 * Insert a new entry between two known consecutive entries.
 *
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 */
static inline void __list_add(struct list_head *new,
                              struct list_head *prev,
                              struct list_head *next)
{
        next->prev = new;
        new->next = next;
        new->prev = prev;
        prev->next = new;
}

/**
 * list_add - add a new entry
 * @new: new entry to be added
 * @head: list head to add it after
 *
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 */
static inline void list_add(struct list_head *new, struct list_head *head)
{
        __list_add(new, head, head->next);
}

/**
 * list_add_tail - add a new entry
 * @new: new entry to be added
 * @head: list head to add it before
 *
 * Insert a new entry before the specified head.
 * This is useful for implementing queues.
 */
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
        __list_add(new, head->prev, head);
}

/*
 * Delete a list entry by making the prev/next entries
 * point to each other.
 *
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 */
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
        next->prev = prev;
        prev->next = next;
}

/**
 * list_del - deletes entry from list.
 * @entry: the element to delete from the list.
 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
 */
static inline void list_del(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
        entry->next = (void *) 0;
        entry->prev = (void *) 0;
}

/**
 * list_del_init - deletes entry from list and reinitialize it.
 * @entry: the element to delete from the list.
 */
static inline void list_del_init(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
        INIT_LIST_HEAD(entry);
}

/**
 * list_move - delete from one list and add as another's head
 * @list: the entry to move
 * @head: the head that will precede our entry
 */
static inline void list_move(struct list_head *list, struct list_head *head)
{
        __list_del(list->prev, list->next);
        list_add(list, head);
}

/**
 * list_move_tail - delete from one list and add as another's tail
 * @list: the entry to move
 * @head: the head that will follow our entry
 */
static inline void list_move_tail(struct list_head *list,
                                  struct list_head *head)
{
        __list_del(list->prev, list->next);
        list_add_tail(list, head);
}

/**
 * list_empty - tests whether a list is empty
 * @head: the list to test.
 */
static inline int list_empty(struct list_head *head)
{
        return head->next == head;
}

static inline void __list_splice(struct list_head *list,
                                 struct list_head *head)
{
        struct list_head *first = list->next;
        struct list_head *last = list->prev;
        struct list_head *at = head->next;

        first->prev = head;
        head->next = first;

        last->next = at;
        at->prev = last;
}

/**
 * list_splice - join two lists
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 */
static inline void list_splice(struct list_head *list, struct list_head *head)
{
        if (!list_empty(list))
                __list_splice(list, head);
}

/**
 * list_splice_init - join two lists and reinitialise the emptied list.
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 *
 * The list at @list is reinitialised
 */
static inline void list_splice_init(struct list_head *list,
                                    struct list_head *head)
{
        if (!list_empty(list)) {
                __list_splice(list, head);
                INIT_LIST_HEAD(list);
        }
}

/**
 * list_entry - get the struct for this entry
 * @ptr:        the &struct list_head pointer.
 * @type:       the type of the struct this is embedded in.
 * @member:     the name of the list_struct within the struct.
 */
#define list_entry(ptr, type, member) \
        ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

/**
 * list_for_each        -       iterate over a list
 * @pos:        the &struct list_head to use as a loop counter.
 * @head:       the head for your list.
 */
#define list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); pos = pos->next)
/**
 * list_for_each_prev   -       iterate over a list backwards
 * @pos:        the &struct list_head to use as a loop counter.
 * @head:       the head for your list.
 */
#define list_for_each_prev(pos, head) \
        for (pos = (head)->prev; pos != (head); pos = pos->prev)

/**
 * list_for_each_safe   -       iterate over a list safe against removal of list entry
 * @pos:        the &struct list_head to use as a loop counter.
 * @n:          another &struct list_head to use as temporary storage
 * @head:       the head for your list.
 */
#define list_for_each_safe(pos, n, head) \
        for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)

#endif
 
分享到:
评论

相关推荐

    python3.6.5参考手册 chm

    PEP 366: Explicit Relative Imports From a Main Module PEP 370: Per-user site-packages Directory PEP 371: The multiprocessing Package PEP 3101: Advanced String Formatting PEP 3105: print As a ...

    DebuggingWithGDB 6.8-2008

    2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 11 12 13 15 16 16 16 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 ...

    Python Cookbook, 2nd Edition

    Building a Dict from a List of Alternating Keys and Values Recipe 4.13. Extracting a Subset of a Dictionary Recipe 4.14. Inverting a Dictionary Recipe 4.15. Associating Multiple Values with ...

    [Go语言入门(含源码)] The Way to Go (with source code)

    2.3 Installing Go on a Linux system...............................................................................16 2.4 Installing Go on an OS X system..................................................

    The way to go

    2.3 Installing Go on a Linux system...............................................................................16 2.4 Installing Go on an OS X system..................................................

    Bochs - The cross platform IA-32 (x86) emulator

    - Fix interrupt vectors for INT 60h-66h (reserved for user interrupt) by setting them to zero - Fix BIOS INT13 function 08 when the number of cylinders on the disk = 1 - I/O Devices - USB HP ...

    dive into python

    2.4. 万物皆对象 2.4.1. 模块导入的搜索路径 2.4.2. 何谓对象? 2.5. 代码缩进 2.6. 测试模块 3. 内置数据类型 3.1. Dictionary 介绍 3.1.1. Dictionary 的定义 3.1.2. Dictionary 的修改 3.1.3. 从 ...

    drupal 6.12

    // $Id: INSTALL.txt,v 1.61.2.4 2008/07/09 19:15:59 goba Exp $ CONTENTS OF THIS FILE --------------------- * Requirements * Optional requirements * Installation * Drupal administration * ...

    diveintopythonzh-cn-pdf 附代码.rar

    2.4. 万物皆对象 ...................................................................................................... 21 2.5. 代码缩进 ...................................................................

    UNIX环境高级编程(第二版,英文版)

    此书对于linux环境编程的同志应该是必读的书,目录如下: Copyright Praise for Advanced Programming in the UNIX® Environment, Second Edition Praise for the First Edition Addison-Wesley ...

    深入Python_zh-cn[中文版]

    2.4. 万物皆对象......................................................................................................21 2.5. 代码缩进....................................................................

    Maven权威指南 很精典的学习教程,比ANT更好用

    2.4. 验证Maven安装 2.5. Maven安装细节 2.5.1. 用户相关配置和仓库 2.5.2. 升级Maven 2.6. 获得Maven帮助 2.7. 使用Maven Help插件 2.7.1. 描述一个Maven插件 2.8. 关于Apache软件许可证 I. Maven实战...

    dp18_ap6330整理完工20170209_1129.7z

    In file included from hardware/broadcom/libbt/include/bt_vendor_brcm.h:34:0, from hardware/broadcom/libbt/src/upio.c:36: out/target/product/tulip-d1/obj_arm/SHARED_LIBRARIES/libbt-vendor_...

    TortoiseSVN中文手册

    2.4. 摘要 ............................................................... 12 3. 配置服务器 ................................................................ 14 3.1. 基于 Apache 的服务器 ..................

    MyQQ(DosQQ) 超小的精简QQ DEV-C++ 源码

    5. utf8.c里添加qqdef.h头文件。 Version 3.13 (2009-3-29) 1. Linux(Ubuntu) version compiled! Version 3.12 (2009-3-22) 1. 用Windows的Sleep代替不推荐的_sleep。 2. 在Mingw32-gcc4.3.3上编译成功。 Version...

    入门学习Linux常用必会60个命令实例详解doc/txt

    不过目前大多数较新的Linux发行版本(包括红旗 Linux、中软Linux、Mandrake Linux等)都可以自动挂装文件系统,但Red Hat Linux除外。 umount 1.作用 umount命令的作用是卸载一个文件系统,它的使用权限是超级...

    免费:makefile编程

    2.4 make如何工作 ............................................................................................................... 13 2.5 指定变量 .......................................................

    SVN操作手册中文版网页格式

    4.4.3. Excluding Items from the Commit List 4.4.4. 提交日志信息 4.4.5. 提交进程 4.5. 用来自别人的修改更新你的工作副本 4.6. 解决冲突 4.6.1. File Conflicts 4.6.2. Tree Conflicts 4.6.2.1. Local ...

    Dive Into Python 中文版

    2.4. 万物皆对象 .........................................................................................................................................16 2.5. 代码缩进 .................................

    KCF源码代码

    The code depends on OpenCV 2.4+ library and is build via cmake toolchain. _________________ Quick start guide for linux: open terminal in the directory with the code $ mkdir build; cd build; cmake ...

Global site tag (gtag.js) - Google Analytics