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

📄 sys_list.c

📁 凌阳32位单片机开发的小游戏
💻 C
字号:
/*************************************************************************
 *  Filename:   list.c
 *  Author:     yfwan  (eMail: yfwan@sunplus.com.cn)   
 *  Tel:        00885-028-87848688-5830
 *  Date:       2004-11-12
 *  Description:Simple doubly linked list implementation.
 *               
 *  Reference:  Linux kernel source code
 *
 *  Version history:
 *------------------------------------------------------------------------
 *	Version   YYYY-MM-DD-INDEX   Modified By         Description
 *  1.2.0     2004-11-12         yfwan               First release
 *	
 ************************************************************************/

/*
 * Simple doubly linked list implementation.
 *
 * Some of the internal functions ("__xxx") are useful when
 * manipulating whole lists rather than single entries, as
 * sometimes we already know the next/prev entries and we can
 * generate better code by using them directly rather than
 * using the generic single-entry routines.
 */
#include "Include/Sys_List.h"

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

/**
 * 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.
 */
INLINE void list_add(LISTHEAD *pnew, LISTHEAD *head)
{
	__list_add(pnew, 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.
 */
INLINE void list_add_tail(LISTHEAD *pnew, LISTHEAD *head)
{
	__list_add(pnew, 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!
 */
INLINE void __list_del(LISTHEAD * prev,
				  LISTHEAD * 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.
 */
INLINE void list_del(LISTHEAD *entry)
{
	__list_del(entry->prev, entry->next);
}

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

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

/**
 * list_splice - join two lists
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 */
INLINE void list_splice(LISTHEAD *list, LISTHEAD *head)
{
	LISTHEAD *first = list->next;

	if (first != list) {
		LISTHEAD *last = list->prev;
		LISTHEAD *at = head->next;

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

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




⌨️ 快捷键说明

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