VC下勉强可用的list

linux内核中的list太好用了,可惜VC编译器不支持 typeof 关键字,将linux内核中的list直接移植过来不能用

修改所有与typeof相关的代码后,终于可以勉强在VC下运行起来了,但是还不完美,list_for_each_entry和list_for_each_entry_safe需要增加一个参数表示变量的类型

修改后的代码如下

#ifndef __EKWIN__LIST__H__
#define __EKWIN__LIST__H__#define LIST_POISON1  ((struct list_head *) 0)
#define LIST_POISON2  ((struct list_head *) 0)
#define HLIST_POISON1  ((struct hlist_node *) 0)
#define HLIST_POISON2  ((struct hlist_node **) 0)#define prefetch(x) (x)
#define likely(x)    (x)
#define unlikely(x)    (x)
#define container_of(ptr, type, member) \(type *)( (char *)ptr - offsetof(type,member) )/** 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.*/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)static inline void INIT_LIST_HEAD(struct list_head *list)
{list->next = list;list->prev = list;
}static inline void __list_add(struct list_head *node,struct list_head *prev,struct list_head *next)
{next->prev = node;node->next = next;node->prev = prev;prev->next = node;
}/*** 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 *node, struct list_head *head)
{__list_add(node, 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 *node, struct list_head *head)
{__list_add(node, 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 = LIST_POISON1;entry->prev = LIST_POISON2;
}/*** list_replace - replace old entry by new one* @old : the element to be replaced* @new : the new element to insert** If @old was empty, it will be overwritten.*/
static inline void list_replace(struct list_head *old,struct list_head *node)
{node->next = old->next;node->next->prev = node;node->prev = old->prev;node->prev->next = node;
}static inline void list_replace_init(struct list_head *old,struct list_head *node)
{list_replace(old, node);INIT_LIST_HEAD(old);
}/*** 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_is_last - tests whether @list is the last entry in list @head* @list: the entry to test* @head: the head of the list*/
static inline int list_is_last(const struct list_head *list,const struct list_head *head)
{return list->next == head;
}
static inline int list_is_first(const struct list_head *list,const struct list_head *head)
{return list->prev == head;
}/*** list_empty - tests whether a list is empty* @head: the list to test.*/
static inline int list_empty(const struct list_head *head)
{return head->next == head;
}/*** list_empty_careful - tests whether a list is empty and not being modified* @head: the list to test** Description:* tests whether a list is empty _and_ checks that no other CPU might be* in the process of modifying either member (next or prev)** NOTE: using list_empty_careful() without synchronization* can only be safe if the only activity that can happen* to the list entry is list_del_init(). Eg. it cannot be used* if another CPU could re-list_add() it.*/
static inline int list_empty_careful(const struct list_head *head)
{struct list_head *next = head->next;return (next == head) && (next == head->prev);
}/*** list_is_singular - tests whether a list has just one entry.* @head: the list to test.*/
static inline int list_is_singular(const struct list_head *head)
{return !list_empty(head) && (head->next == head->prev);
}static inline void __list_cut_position(struct list_head *list,struct list_head *head, struct list_head *entry)
{struct list_head *new_first = entry->next;list->next = head->next;list->next->prev = list;list->prev = entry;entry->next = list;head->next = new_first;new_first->prev = head;
}/*** list_cut_position - cut a list into two* @list: a new list to add all removed entries* @head: a list with entries* @entry: an entry within head, could be the head itself*    and if so we won't cut the list** This helper moves the initial part of @head, up to and* including @entry, from @head to @list. You should* pass on @entry an element you know is on @head. @list* should be an empty list or a list you do not care about* losing its data.**/
static inline void list_cut_position(struct list_head *list,struct list_head *head, struct list_head *entry)
{if (list_empty(head))return;if (list_is_singular(head) &&(head->next != entry && head != entry))return;if (entry == head)INIT_LIST_HEAD(list);else__list_cut_position(list, head, entry);
}static inline void __list_splice(const struct list_head *list,struct list_head *prev,struct list_head *next)
{struct list_head *first = list->next;struct list_head *last = list->prev;first->prev = prev;prev->next = first;last->next = next;next->prev = last;
}/*** list_splice - join two lists, this is designed for stacks* @list: the new list to add.* @head: the place to add it in the first list.*/
static inline void list_splice(const struct list_head *list,struct list_head *head)
{if (!list_empty(list))__list_splice(list, head, head->next);
}/*** list_splice_tail - join two lists, each list being a queue* @list: the new list to add.* @head: the place to add it in the first list.*/
static inline void list_splice_tail(struct list_head *list,struct list_head *head)
{if (!list_empty(list))__list_splice(list, head->prev, 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, head->next);INIT_LIST_HEAD(list);}
}/*** list_splice_tail_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.** Each of the lists is a queue.* The list at @list is reinitialised*/
static inline void list_splice_tail_init(struct list_head *list,struct list_head *head)
{if (!list_empty(list)) {__list_splice(list, head->prev, 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) \container_of(ptr, type, member)/*** list_first_entry - get the first element from a list* @ptr:    the list head to take the element from.* @type:    the type of the struct this is embedded in.* @member:    the name of the list_struct within the struct.** Note, that list is expected to be not empty.*/
#define list_first_entry(ptr, type, member) \list_entry((ptr)->next, type, member)
#define list_last_entry(ptr, type, member) \list_entry((ptr)->prev, type, member)/*** list_for_each    -    iterate over a list* @pos:    the &struct list_head to use as a loop cursor.* @head:    the head for your list.*/
#define list_for_each(pos, head) \for (pos = (head)->next; prefetch(pos->next), pos != (head); \pos = pos->next)/*** __list_for_each    -    iterate over a list* @pos:    the &struct list_head to use as a loop cursor.* @head:    the head for your list.** This variant differs from list_for_each() in that it's the* simplest possible list iteration code, no prefetching is done.* Use this for code that knows the list to be very short (empty* or 1 entry) most of the time.*/
#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 cursor.* @head:    the head for your list.*/
#define list_for_each_prev(pos, head) \for (pos = (head)->prev; prefetch(pos->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 cursor.* @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)/*** list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry* @pos:    the &struct list_head to use as a loop cursor.* @n:        another &struct list_head to use as temporary storage* @head:    the head for your list.*/
#define list_for_each_prev_safe(pos, n, head) \for (pos = (head)->prev, n = pos->prev; \prefetch(pos->prev), pos != (head); \pos = n, n = pos->prev)/*** list_for_each_entry    -    iterate over list of given type* @pos:    the type * to use as a loop cursor.* @head:    the head for your list.* @member:    the name of the list_struct within the struct.*/
#define list_for_each_entry(postp, pos, head, member)                \for (pos = list_entry((head)->next, postp, member);    \prefetch(pos->member.next), &pos->member != (head);     \pos = list_entry(pos->member.next, postp, member))/*** list_for_each_entry_safe - iterate over list of given type safe against removal of list entry* @pos:    the type * to use as a loop cursor.* @n:        another type * to use as temporary storage* @head:    the head for your list.* @member:    the name of the list_struct within the struct.*/
#define list_for_each_entry_safe(postp, pos, n, head, member)            \for (pos = list_entry((head)->next, postp, member),    \n = list_entry(pos->member.next, postp, member);    \&pos->member != (head);                     \pos = n, n = list_entry(n->member.next, postp, member))/** Double linked lists with a single pointer list head.* Mostly useful for hash tables where the two pointer list head is* too wasteful.* You lose the ability to access the tail in O(1).*/struct hlist_head {struct hlist_node *first;
};struct hlist_node {struct hlist_node *next, **pprev;
};#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
static inline void INIT_HLIST_NODE(struct hlist_node *h)
{h->next = NULL;h->pprev = NULL;
}static inline int hlist_unhashed(const struct hlist_node *h)
{return !h->pprev;
}static inline int hlist_empty(const struct hlist_head *h)
{return !h->first;
}static inline void __hlist_del(struct hlist_node *n)
{struct hlist_node *next = n->next;struct hlist_node **pprev = n->pprev;*pprev = next;if (next)next->pprev = pprev;
}static inline void hlist_del(struct hlist_node *n)
{__hlist_del(n);n->next = HLIST_POISON1;n->pprev = HLIST_POISON2;
}static inline void hlist_del_init(struct hlist_node *n)
{if (!hlist_unhashed(n)) {__hlist_del(n);INIT_HLIST_NODE(n);}
}static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{struct hlist_node *first = h->first;n->next = first;if (first)first->pprev = &n->next;h->first = n;n->pprev = &h->first;
}/* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n,struct hlist_node *next)
{n->pprev = next->pprev;n->next = next;next->pprev = &n->next;*(n->pprev) = n;
}static inline void hlist_add_after(struct hlist_node *n,struct hlist_node *next)
{next->next = n->next;n->next = next;next->pprev = &n->next;if(next->next)next->next->pprev  = &next->next;
}/** Move a list from one list head to another. Fixup the pprev* reference of the first entry if it exists.*/
static inline void hlist_move_list(struct hlist_head *old,struct hlist_head *node)
{node->first = old->first;if (node->first)node->first->pprev = &node->first;old->first = NULL;
}#define hlist_entry(ptr, type, member) container_of(ptr,type,member)#define hlist_for_each(pos, head) \for (pos = (head)->first; pos; \pos = pos->next)#define hlist_for_each_safe(pos, n, head) \for (pos = (head)->first; pos; \pos = n)/*** hlist_for_each_entry    - iterate over list of given type* @tpos:    the type * to use as a loop cursor.* @pos:    the &struct hlist_node to use as a loop cursor.* @head:    the head for your list.* @member:    the name of the hlist_node within the struct.*/
#define hlist_for_each_entry(tpos, pos, head, member)             \for (pos = (head)->first;                     \pos && ({ prefetch(pos->next); 1;}) &&             \({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \pos = pos->next)/*** hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry* @tpos:    the type * to use as a loop cursor.* @pos:    the &struct hlist_node to use as a loop cursor.* @n:        another &struct hlist_node to use as temporary storage* @head:    the head for your list.* @member:    the name of the hlist_node within the struct.*/
#define hlist_for_each_entry_safe(tpos, pos, n, head, member)          \for (pos = (head)->first;                     \pos && ({ n = pos->next; 1; }) &&                  \({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \pos = n)#define list_next(ptr) \((ptr)->member.next)
#define list_prev(ptr, member) \((ptr)->member.prev)static inline int list_count(struct list_head *head)
{int count = 0;struct list_head *pos;list_for_each(pos, head) {count++;}return count;
}/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_32
#define hash_long(val, bits) hash_32(val, bits)static inline unsigned int hash_32(unsigned int val, unsigned int bits)
{/* On some cpus multiply is faster, on others gcc will do shifts */unsigned int hash = val * GOLDEN_RATIO_PRIME_32;/* High bits are more random, so use them. */return hash >> (32 - bits);
}static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
{return hash_long((unsigned long)ptr, bits);
}#endif // __EKWIN__LIST__H__

 

转载于:https://www.cnblogs.com/cppboy/p/3717632.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/375904.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

当执行游戏0xc000007b错误的解决方法

如图,这个错误使无数玩家烦恼。 出现这个错误,可能是硬件的问题,也可能是软件的问题。可是,因为硬件引起该问题的概率非常小,而且除了更换硬件之外没有更好的解决方法,因此本文将具体介绍怎样通过软件解决此…

android触屏音文件地址,Android音视频-音频采集

Android的音视频开发是我暂定的一个职业发展的一个方向,通过自学记录一些记了又忘记的知识。音频基础知识采样率(samplerate)蓝色代表模拟音频信号,红色的点代表采样得到的量化数值。采用就是把模拟信号数字化的过程,不仅仅是音频需要采样&am…

平衡二叉树,AVL树之图解篇

学习过了二叉查找树,想必大家有遇到一个问题。例如,将一个数组{1,2,3,4}依次插入树的时候,形成了图1的情况。有建立树与没建立树对于数据的增删查改已经没有了任何帮助,反而增添了维护的成本。而只有建立的树如图2,才能…

窗体

GDI:图形设备接口 所有能够将电子信号转换成图像显示的设备是图形设备, 常见的图形设备有显示器,打印机。 Winform封装了GDI底层的接口,提供一组面向对象的接口,供我们使用 Partial关键字,用他修饰的类叫分布类/部分类…

android程序到处apk,导出已安装到手机中程序的apk文件

查看该手机所有安装包的包名,输入adb shell pm list packages找到你要导出的包名获取该安装apk的路径,输入adb shell pm path com.pfoc.myacurite得到包所在路径:导出文件,adb pull /data/app/com.pfoc.myacurite-1/base.apk /Use…

数据结构--顺序栈

栈&#xff1a;限定仅在表尾进行插入或删除操作的线性表&#xff0c;对栈来说&#xff0c;表尾端为栈顶&#xff0c;表头端为栈底。 本文实现了顺序栈的表示和相关函数操作&#xff0c;以及一些验证性代码。 #include<stdio.h> #include<stdlib.h> #include<w…

Mysql 的一些基本用法

一、增加字段 alter table students add IsImportJcxx int set default 0 COMMENT 是否导入基础信息平台 1 是导入; 二、删除字段 alter table provincestudentinfo drop column NativePlace; 三、创建表 CREATE TABLE 表名 ( IconId int not null auto_increment, 字段名 …

Python 文件的输入与输出

1. 文本文件的读写主要通过open()所构建的文件对象来实现。我们打开一个文件&#xff0c;并使用一个对象来表示该文件 , f open(d&#xff0c;r) 其中d是文件名&#xff0c;r是模式 "r" 文件只读,使用 f.write()会报错 "w" 用于写入&#xff0c;每次使用f…

查询表的内容

1&#xff1a;as给表另外命名 2&#xff1a;desc倒序 3&#xff1a;order by分组 4&#xff1a;select*form表名where条件转载于:https://www.cnblogs.com/chen1101465910/p/3719944.html

人之为生也&#xff0c;凡不破者亦难立之。纵所思之&#xff0c;生而顺之者&#xff0c;亦难成也。然吾之路也&#xff0c;亦难行之&#xff0c;至此二十有余&#xff0c;虽无半百之所历&#xff0c;亦无顺途&#xff0c;每及思之&#xff0c;慨之多也。 偶有所感&#xff0c;念…

Delphi 一些函数解释

AdjustWindowRect 给定一种窗口样式&#xff0c;计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconicWindows 排列一个父窗口的最小化子窗口 AttachThreadInput 连接线程输入函数 BeginDeferWindowPos 启动构建一系列新窗口位置的过…

盒子模型的总结

转载于:https://www.cnblogs.com/zy2012/p/3725677.html

ubuntu node.js Binaries方式安装(二进制文件安装)

node.js在windows下有安装文件&#xff0c;直接一路下一步就可以了&#xff0c;但大家都知道在windows下用node.js总会遇到一些问题&#xff0c;所以就会用到linux。 看到网上几乎是在linux下编译安装node.js。感觉很奇怪&#xff0c;其实官网直接有 node.js linux binaries文…

maven generating project in batch mode hang

现象&#xff1a; 执行 archetype:generate 的时候&#xff0c;会产生[INFO] Generating project in Batch mode原因是&#xff1a;网速问题&#xff0c; 解决方法&#xff1a; 设置maven不要从远程服务器上获取catalog&#xff0c;增加参数-DarchetypeCataloginternal 如何在i…

android手机生成pdf格式文件,Android根据pdf模板生成pdf文件

1 public voidFillPdfTemplate(String id) {2 android.icu.text.SimpleDateFormat simpleDateFormat 3 new android.icu.text.SimpleDateFormat("HHmmss");//HH:mm:ss4 //设置默认时区5 simpleDateFormat.setTimeZone(android.icu.util.TimeZone.getTimeZone("G…

栈的应用--数制转换

十进制N和其他d进制 N(N div d)XdN mod d &#xff08;其中&#xff1a;div为整除运算&#xff0c;mod为求余运算&#xff09; void conversion(){SqStack S;int N;SElemType e;Init_Stack(S);scanf("%d",&N);while(N){Push(S,N%8);NN/8;}while(!Stack_Empty(S…

radio按钮点击文字选中按钮

<input type"radio" name"name" id"rd" value" " /><label for"rd">测试</label> 转载于:https://www.cnblogs.com/kevin1988/p/3727041.html

tokumx经营报表

#见数据库列表 show dbs#切换/创建数据库(当创建一个集合(table)的时候会自己主动创建当前数据库)use admin;#添加用户 db.addUser("zhoulf ","123456",true)#更改password&#xff08;为已经存在的用户更改password&#xff09; db.addUser("zhoulf …

微博 Android 启动广告,使用Xposed去除微博国际版的启动广告

本文同步更新于旺仔的个人博客&#xff0c;访问可能有点慢&#xff0c;多刷新几次。前面有篇文章已经介绍了如何创建Xposed模块的文章了&#xff0c;这篇就让我们来实现一个简单的去除启动广告的功能吧。起因为什么要是要去掉微博国际版的开屏广告呢&#xff0c;因为广告烦人啊…

鸽巢原理

鸽巢原理&#xff1a; n1个鸽子放入n个窝中&#xff0c;至少有一个窝含有两只鸽子 Find a multipleTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5590 Accepted: 2434 Special JudgeDescription The input contains N natural (i.e. positive integer) numbers…