当前位置: 首页 > news >正文

网站免费源码不用下载如何给网站添加ico

网站免费源码不用下载,如何给网站添加ico,装修公司网站建设费用,wordpress mysql 分表源码基于#xff1a;Linux 5.10 0.前言 container_of() 这个宏函数在Linux 内核中使用的频率还是很多的。网上关于 container_of 使用的优秀文章也很多#xff0c;之所以笔者也写一篇#xff0c;一是想更新下最新代码中的使用#xff0c;二是融入些自己的拙见#xff0c;…源码基于Linux 5.10 0.前言 container_of() 这个宏函数在Linux 内核中使用的频率还是很多的。网上关于 container_of 使用的优秀文章也很多之所以笔者也写一篇一是想更新下最新代码中的使用二是融入些自己的拙见方便自己回头查看也希望能有助于后来读者。 1. 源码 include/linux/kernel.h/*** container_of - cast a member of a structure out to the containing structure* ptr: the pointer to the member.* type: the type of the container struct this is embedded in.* member: the name of the member within the struct.**/ #define container_of(ptr, type, member) ({ \void *__mptr (void *)(ptr); \BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)-member) \!__same_type(*(ptr), void), \pointer type mismatch in container_of()); \((type *)(__mptr - offsetof(type, member))); })该宏函数主要用于通过一个结构体中成员的地址转换获得该结构体的起始地址。 该宏函数有三个参数 ptr该成员变量的地址type该成员是被包含在哪个结构体也就是最终想要获取起始地址的结构体类型member该成员在结构体中的名称也就是ptr 指向的成员名称与 ptr 是对应的 该宏函数共做了三件事情 将第一个参数即成员指针强转成 void*调用 BUILD_BUG_ON_MSG() 进行编译assert要求 ptr 确实是参数 member 对应的结构体成员且 ptr 已经转换成 void*调用 offsetof() 计算成员member 在结构体中的偏移量进而计算出结构体的起始地址并进行返回 1.1 BUILD_BUG_ON_MSG() include/linux/build_bug.h/*** BUILD_BUG_ON_MSG - break compile if a condition is true emit supplied* error message.* condition: the condition which the compiler should know is false.** See BUILD_BUG_ON for description.*/ #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) 当condition 为true 时会退出编译并报错。 扩展后可以看到 BUILD_BUG_ON_MSG() 为 #define BUILD_BUG_ON_MSG(cond, msg) \do { \extern void __compiletime_assert_2(void)__attribute__((__error__(msg))); \if (!(condition)) \__compiletime_assert_2(); \} while (0) 其中 __compiletime_assert_N() 是gcc 定义断言函数N 是通过 __COUNTER__ 计数得来的。 另外想要调用这个 gcc 断言函数需要定义 __OPTIMIZE__即 gcc 编译的时候需要加上优化选项 -Onn 是大于0的。 1.2 offsetof() include/linux/stddef.h#ifdef __compiler_offsetof #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) #else #define offsetof(TYPE, MEMBER) ((size_t)((TYPE *)0)-MEMBER) #endif 其中 TYPE 是结构体的类型MEMBER 是成员名称。 当定义 __compiler_offsetof 时调用 __compiler_offsetof() 宏函数其实就是调用 gcc 的内置函数 __builtin_offsetof()。 当没有定义 __compiler_offsetof 时通过 ((TYPE *)0)-MEMBER 获取成员变量的地址0 是起始地址那得到的成员变量的地址就是偏移量。 1.3 返回值 当通过 offsetof() 获取到偏移量之后使用 ptr - offset 就是结构体的起始地址了。 之所以利用这种方式是因为结构体的内存在内存空间中是连续的。 结构体起始地址(也是第一个成员的首地址) 与成员N 相差 offsetcontainer_of() 就是利用成员的首地址与offset进而求出该结构体的起始地址。 2. 实例 drivers/dma-buf/heaps/system_heap.cstatic void system_heap_buf_free(struct deferred_freelist_item *item,enum df_reason reason) {struct system_heap_buffer *buffer;struct sg_table *table;struct scatterlist *sg;int i, j;buffer container_of(item, struct system_heap_buffer, deferred_free);... } Linux 内核中使用 container_of() 的地方很多这里用 dma-buf 中的一个函数为例。 通过上面源码分析很容易理解此处 通过结构体 system_heap_buffer 的成员变量 deffered_free 的地址 item求得该结构体的起始地址。 结构体的源码如下  drivers/dma-buf/heaps/system_heap.cstruct system_heap_buffer {struct dma_heap *heap;struct list_head attachments;struct mutex lock;unsigned long len;struct sg_table sg_table;int vmap_cnt;void *vaddr;struct deferred_freelist_item deferred_free;bool uncached; };
http://www.yutouwan.com/news/415368/

相关文章:

  • 丘里奇网站排名网站建设十年杜绝模板
  • 网站开发的背景意义微信做代理的网站
  • 南通市优普网站建设建设网站要多少钱
  • 南通建设中标查询网站公司找人做的网站到现在还没出来
  • 打开网站搜索设计必备网站
  • 做PHP网站前端网站进不去微信如何制作网页
  • 查看网站访问量如何帮客户做网站
  • 电商网站设计线路图p2p网站的建设
  • 京东商城 网站建设灌南县规划局网站一品嘉苑规划建设
  • 旅游网站建设方案后台wordpress postline
  • 金融公司做网站域名中国现货交易网官网
  • 聊城东昌府区建设路小学网站宿迁网络科技有限公司
  • 域名怎么绑定自己网站免费个人网站建站
  • 网站建设颜色代码表广州微网站建设市场
  • 旅游网站建设与规划wordpress文章部分展示
  • 个人的网站怎么备案表静态网页模板免费下载的网站
  • 呼和浩特电子商务网站建设微信里怎么进入自己的公众号
  • 网站建设一般多少钱要如何选择什么网站可以找人做软件
  • 深圳官方网站网站建设格局
  • 做签到的网站江门关键词排名优化
  • 17zwd一起做网站广州新塘望城经济建设开区门户网站
  • 河南省住房和城乡建设厅官方网站新建网站推广给企业
  • 如何在各个购物网站之间做差价大连网站建设招标
  • 一个叫mit做app的网站火狐浏览器下载手机版
  • 部队网站制作3d建模平台
  • 房屋中介的网站怎么建设114黄页网推广
  • 网站建设书籍赚客吧先做网站还是做APP
  • 中小学 网站建设 通知写文章一篇30元兼职
  • 外国网站在中国做推广网站开发感受
  • 情人节网站怎么做wordpress文章中文版