
Peter Dimov wrote: [...]
xadd is branchless; it just returns the old value, whereas inc doesn't. MSVC always generates lock xadd, even for _InterlockedIncrement, BTW.
Well, maybe. But you need value neither for increments nor decrements. (I mean that for decrements you can simply rely on ZF flag). Oder? [...]
void release() // nothrow { if( atomic_exchange_and_add( &use_count_, -1 ) == 1 ) { dispose();
if( (long volatile&)weak_count_ == 1 ) // no weak ptrs { destroy(); } else { weak_release(); } } }
?
Nah. For the sake of killing C/C++ volatiles rather sooner than later, I strongly suggest that you hide that load in asm. Just add load+cmp followed by ZF branch prior to "lock dec" which also sets ZF, IIRC. regards, alexander.