I'm looking for a function that presents a high level D interface to an atomic CAS on Intel x86.
I know I can do it with inline ASM (and if needed I will), but I'd rather just grab code from someone else if I can.
I'm looking for a function that presents a high level D interface to an atomic CAS on Intel x86.
I know I can do it with inline ASM (and if needed I will), but I'd rather just grab code from someone else if I can.
From the documentation at: http://www.digitalmars.com/d/2.0/overview.html
Inline Assembler
Device drivers, high performance system applications, embedded systems, and specialized code sometimes need to dip into assembly language to get the job done. While D implementations are not required to implement the inline assembler, it is defined and part of the language. Most assembly code needs can be handled with it, obviating the need for separate assemblers or DLL's.
Many D implementations will also support intrinsic functions analogously to C's support of intrinsics for I/O port manipulation, direct access to special floating point operations, etc.
So you could in theory use the CMPXCHG directly.
Edit
You may want look at: http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=4277
It does take a while to load for some reason, but it is using the CMPXCHG instruction internally, it should be trivial to retool it for your purposes.