atomic64_add_and_return
Function Usage
This function is used to perform an atomic addition on two long integers and return the result.
Procedure
Rewrite the assembly code segments.
Code on the x86 platform:
static inline long atomic64_add_and_return(long i, atomic64_t *v)
{
long i = i;
asm_volatile_(
"lock ; "
"xaddq %0, %1;"
: "=r"(i)
: "m"(v->counter), "0"(i));
return i + __i;
}
static inline void prefetch(void *x)
{
asm volatile("prefetcht0 %0" ::"m"(*(unsigned long *)x));
}
On the Kunpeng platform, use the GCC built-in functions to implement the following instructions:
static __inline__ long atomic64_add_and_return(long i, atomic64_t *v)
{
return __sync_add_and_fetch(&((v)->counter), i);
}
Parent topic: Replacing x86 Atomic Operation Functions