Dear All,
I'm now customizing SGI STL for my own purposes on my Linux box. And I'd like to efficiently implement an atomic (thread safe) swap between two integers size of a general purpose register.
Below is the Assembly code in the Intel format, which gcc doesn't compile at all:
unsigned long _Atomic_swap(unsigned long* __p, unsigned long __q)
{
asm("mov ecx, dword ptr [esp+4]"); // Load ECX with __p
asm("mov edx, dword ptr [esp+8]"); // Load EDX with __q
asm("mov eax, dword ptr [ecx]"); // Load EAC with
// the current value
// in __p
asm("label: lock cmpxchg dword ptr [ecx], edx");
// if (EAX == [ECX]),
// [ECX] = EDX
asm("jne short label"); // if (EAX != [ECX]),
// repeat last
// instruction
asm("retn 8"); // return to caller
Can anyone help me out with the correct syntax.Quote:}
Thanks a lot in advance.
Kiril.
--
Posted from 172.16.27.62, 172.16.17.153 via proxy [212.72.53.70] by way of mx5.port.ru [194.67.23.40]
via Mailgate.ORG Server - http://www.Mailgate.ORG