spin_lock_irqsave()中的flags初始化

11310阅读 0评论2013-05-07 testh
分类:LINUX

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

上一篇:ubuntu12.4下tftp设置(精华)
下一篇:fedora18 安装samba