spin_lock_irqsave()中的flags初始化

在使用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:
#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实在有点别扭。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值