Subject: Re: Atomic ops API
To: NetBSD Kernel Technical Discussion List <tech-kern@netbsd.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: tech-kern
Date: 03/13/2007 13:41:33
On Mon, Mar 12, 2007 at 11:28:47PM -0700, Jason Thorpe wrote:
> The API is borrowed from Solaris.  There is one major difference,  
> however.  Solaris defines "cas" as COMPARE-AND-SWAP, returning the  
> previous value of the memory cell.  I have defined it as COMPARE-AND- 
> STORE, returning true if the ops succeeds, or false otherwise.  The  
> reason for this is because some platforms will have extreme difficulty  
> implementing COMPARE-AND-SWAP, whereas COMPARE-AND-STORE is somewhat  
> easier for these platforms.

This is just an additional branch to get compare-and-swap, right? I
don't have a problem with the compare-and-store, that's often
preferable, actually.

> 1. 8-bit and 16-bit operations are to be used sparingly because, on  
> some (most?) platforms, they are extremely expensive compared to the  
> corresponding 32-bit (or 64-bit, if available) operation.

getting the current value, bitmasking, cas? possible retry if the
changed bits for not the one we wanted to change. Right?

Joerg