| 
 Q:  We are converting our Nubus card to a PCI card, and we need to know how to
implement read-modify-write to lock the PCI target device. A:  Designing PCI Cards and Drivers, which is on the PCI Driver Development
Kit (DDK), explains this as follows: Atomic Memory Operations The Driver Services Library provides the following 32-, 16-, and 8-bit atomic
memory operations for use by device drivers.  
	| 
Boolean CompareAndSwap(long oldValue, long newValue, long *Value);
SInt32            IncrementAtomic( SInt32 *value );
SInt32            DecrementAtomic( SInt32 *value );
SInt32            AddAtomic( SInt32 amount, SInt32 *value );
UInt32        BitAndAtomic( UInt32 mask, UInt32 *value );
UInt32        BitOrAtomic( UInt32 mask, UInt32 *value );
UInt32        BitXorAtomic( UInt32 mask, UInt32 *value );
SInt8             IncrementAtomic8( SInt8 *value );
SInt8             DecrementAtomic8( SInt8 *value );
SInt8             AddAtomic8( SInt32 amount, SInt8 *value );
UInt8             BitAndAtomic8( UInt32 mask, UInt8 *value );
UInt8             BitOrAtomic8( UInt32 mask, UInt8 *value );
UInt8             BitXorAtomic8( UInt32 mask, UInt8 *value );
SInt16            IncrementAtomic16( SInt16 *value );
SInt16            DecrementAtomic16( SInt16 *value );
SInt16            AddAtomic16( SInt32 amount, SInt16 *value );
UInt16        BitAndAtomic16( UInt32 mask, UInt16 *value );
UInt16        BitOrAtomic16( UInt32 mask, UInt16 *value );
UInt16        BitXorAtomic16( UInt32 mask, UInt16 *value );
 |  The
atomic routines perform various operations on the memory address specified by
value:  
IncrementAtomicincrements the value by one andDecrementAtomicdecrements it
by one. These functions return the value as it was before the change.AddAtomicadds the specified amount to the value at the specified address and returns the result.BitAndAtomicperforms a logical and operation between the bits of the specified mask and the value at the specified address, returning the result. Similarly,BitOrAtomicperforms a logical or operation andBitXorAtomicperforms a logicalXORoperation.The CompareAndSwaproutine compares the value at the specified address witholdValue. The value ofnewValueis written to the specified address only ifoldValueand the value at the specified address are equal.CompareAndSwapreturns true ifnewValueis written to the specified address; otherwise it returns false. A false return value does not imply thatoldValueand the value at the specified address are not equal; it only implies thatCompareAndSwapdid not write newValue to the specified address. These routines take logical address pointers and ensure that the operations are
atomic with respect to all devices (for example, other processors, DMA engines)
that participate in the coherency architecture of the Macintosh system. 
	| 
TestAndSet        (UInt32            theBit
                  UInt8            *theAddress);
TestAndClear    (UInt32            theBit
                  UInt8               *theAddress);
theBit            The bit number in the range 0 through 7.
theAddress        The address of the byte in which the bit is located.
 |  TestAndSetandTestAndClearset and clear a single bit in a byte at a specified
address.
 |