Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1070084
  • 博文数量: 132
  • 博客积分: 612
  • 博客等级: 中士
  • 技术积分: 1389
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-14 16:06
文章分类

全部博文(132)

文章存档

2015年(2)

2014年(55)

2013年(53)

2012年(2)

2011年(20)

分类: LINUX

2013-05-07 17:55:22

在使用spin_lock_irqsave()时发现它的第2个参数没有初始化就直接传过去了,看着有些奇怪,就在网上搜了一下。起始应该看看代码的。。。。

引用地址
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实在有点别扭。

阅读(10777) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~