我有一个关于在 ARM 平台上的 Linux 内核中实现互斥锁的问题。
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
int __ex_flag, __res;
__asm__ (
"ldrex %0, [%2] \n\t"
"sub %0, %0, #1 \n\t"
"strex %1, %0, [%2] " //for ARMv6+ ,kernel use ldrex/strex implement mutex lock.
: "=&r" (__res), "=&r" (__ex_flag)
: "r" (&(count)->counter)
: "cc","memory" );
__res |= __ex_flag; //How can we know the "strex" operation is successfully finished or not?
//The status of (atomic_t *count) is different in these two cases.
//I wonder this is a bug ,or I did not understand the lock mechanism so well.
if (unlikely(__res != 0))
fail_fn(count);
}
非常感谢您对此问题的建议或回答。任何事情都会受到赞赏。
有关源代码的更多信息,请参阅;http://lxr.oss.org.cn/source/arch/arm/include/asm/mutex.h?v=3.5.2;a=arm
文件路径为:
linux-3.5.2/arch/arm/include/asm/mutex.h