Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-07-07 17:17:07


Tomas Puverle wrote:

> Here's my version:
>
> inline uint32_t compareAndSwap(uint32_t * dest_, uint32_t compare_,
> uint32_t swap_)
> {
> __asm__ __volatile__("cas %0, %1, %2 \n\t"
> : "+m" (*dest_), "+r" (compare_)
> : "r" (swap_)
> : );
> return compare_;
> }

Is it possible to make this:

inline bool compareAndSwap(uint32_t * dest_, uint32_t * compare_, uint32_t
swap_ );

such that compare_ receives the old value and the function returns true on
success, false on failure?

I tried finding information on whether the CAS instruction sets any flags
but the online manuals are of little use.

Also, where is uint32_t defined? We probably need to include the appropriate
header.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk