spin_lock_irqsave()中的flags初始化
2015-11-30 17:00
381 查看
在使用spin_lock_irqsave()时发现它的第2个参数没有初始化就直接传过去了,看着有些奇怪,就在网上搜了一下。起始应该看看代码的。。。。
引用地址 http://www.linuxquestions.org/questions/programming-9/spin_lock_irqsave-365299/
Hi guys
void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
real example:
+void object_put(struct object *obj)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&cache_lock, flags);
+ __object_put(obj);
+ spin_unlock_irqrestore(&cache_lock, flags);
+}
How the flags can be saved in flags variable if the flags variable is passed as a normal variable not as reference or pointer to the spin_lock_irqsave
What do I misunderstand???
How this mechanism works???
Thanks in advance
spin_lock_irqsave is actually a macro defined in "linux/spinlock.h" as:
Code:
on SMP systems and
Code:
otherwise.
I suppose somewhere in the world of nested macros, it gets dereferenced appropriately on non-SMP systems. Or not used at all.
主要是编译的时候它提示:
linux-kernelM/arch/arm/include/asm/irqflags.h:151:2: warning: 'flags' may be used uninitialized in this function [-Wuninitialized]
看了上面的解释和源码后知道背后都是宏在传来传去的,披着函数的外皮干着宏的勾当,世风日下啊。
为了去掉编译警告就在源码中给他初始化为0了,反正用的时候还会赋值的。
要不满屏的warning实在有点别扭。
引用地址 http://www.linuxquestions.org/questions/programming-9/spin_lock_irqsave-365299/
Hi guys
void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
real example:
+void object_put(struct object *obj)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&cache_lock, flags);
+ __object_put(obj);
+ spin_unlock_irqrestore(&cache_lock, flags);
+}
How the flags can be saved in flags variable if the flags variable is passed as a normal variable not as reference or pointer to the spin_lock_irqsave
What do I misunderstand???
How this mechanism works???
Thanks in advance
spin_lock_irqsave is actually a macro defined in "linux/spinlock.h" as:
Code:
#define spin_lock_irqsave(lock, flags) flags = _spin_lock_irqsave(lock)
on SMP systems and
Code:
#define spin_lock_irqsave(lock, flags) _spin_lock_irqsave(lock, flags)
otherwise.
I suppose somewhere in the world of nested macros, it gets dereferenced appropriately on non-SMP systems. Or not used at all.
主要是编译的时候它提示:
linux-kernelM/arch/arm/include/asm/irqflags.h:151:2: warning: 'flags' may be used uninitialized in this function [-Wuninitialized]
看了上面的解释和源码后知道背后都是宏在传来传去的,披着函数的外皮干着宏的勾当,世风日下啊。
为了去掉编译警告就在源码中给他初始化为0了,反正用的时候还会赋值的。
要不满屏的warning实在有点别扭。
相关文章推荐
- mysql存储过程
- JS组件系列——Bootstrap文件上传组件:bootstrap fileinput
- Fiona中文文档
- C++primer plus第六版课后编程练习答案11.4
- CMakeList.txt学习
- 第十三周项目2 Dijkstra算法的验证
- 【论文笔记】利用事件影响域挖掘时空关联规则
- 第十四周--分块查找
- 第十四周项目一 (2) 验证算法——分块查找
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 【第13周 项目3 - Dijkstra算法的验证】
- 初学Redis(1)——认识Redis
- 写下这篇东西,给我未来的爱人。【沫是女王】
- php页面操作超时
- python地理处理包——pyproj官方中文文档
- 十四周 项目1-2 分块查找
- iOS自定义UIAlertView的小tips
- 抗衰老,吃这些食物越来越年轻
- mysql prompt的用法详解
- mysql prompt的用法详解