0
votes

My gcc cross compiler doesn't support Built-in functions for atomic memory access. How i can implement the following function, using inline assembly for Sparc V8 architecture:

long __sync_val_compare_and_swap (long *ptr, long oldval long newval)
{
....
}

Those builtin perform an atomic compare and swap. That is, if the current value of *ptr is oldval, then write newval into *ptr.

1
test_cas.c:(.text+0x70): undefined reference to `atomic_cas_8'G-71
Linking with Solaris libc required ... or else, take the sources from src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/common/… to get it.FrankH.

1 Answers

2
votes

SPARC V8 doesn't have a CAS instruction, so you'll have to emulate it somehow. E.g. use the C-like pseudocode for CAS at http://www.oracle.com/technetwork/server-storage/solaris10/index-142944.html and use a static pthread mutex to ensure the atomicity of the atomic {} region.