25 Jul
2007
25 Jul
'07
11:28 p.m.
Baruch Zilber wrote:
You are right. I fixed it and here is the new implementation:
inline void atomic_increment( int * pw ) { _Asm_fetchadd(_FASZ_W, _SEM_ACQ, (void*)pw, +1, _LDHINT_NONE); }
inline int atomic_decrement( int * pw ) { int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_ACQ, (void*)pw, -1, _LDHINT_NONE)); if (1 == r) { _Asm_mf(); }
return r - 1; }
Hmm. Why did you switch to _SEM_ACQ? atomic_increment should use _REL because it's rumored to be cheaper, and atomic_decrement needs to use _REL for correctness.