
7 Jul
2006
7 Jul
'06
9:17 p.m.
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.