I have a question about mutex implementation in Linux kernel on an ARM platform.
__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);
}
Thank you very much for your suggestion or answer to this question. Anything will be appreciated.
For more information about the source code, please refer to ; http://lxr.oss.org.cn/source/arch/arm/include/asm/mutex.h?v=3.5.2;a=arm
The file path is:
linux-3.5.2/arch/arm/include/asm/mutex.h