On Solaris, it’s better not to write your own code for this (neither on SPARC nor on x86); rather, use functions atomic_cas(3C)
for this purpose:
static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
unsigned long new, int size)
{
switch (size) {
case 1: return atomic_cas_8(ptr, (unsigned char)old, (unsigned char)new);
case 2: return atomic_cas_16(ptr, (unsigned short)old, (unsigned short)new);
case 4: return atomic_cas_32(ptr, (unsigned int)old, (unsigned int)new);
#ifdef _LP64
case 8: return atomic_cas_64(ptr, old, new);
#endif
default: break;
}
return old;
}
This will be done for Solaris.
:, , SPARC (v8 +, aka UltraSPARC) - " ", aka CAS
. (sparc ). 32- 64- (CASX
) , 8/16- 32bit CAS
, /. - , .
Edit2: ( Solaris libc).