
21 Dec
2009
21 Dec
'09
8:31 p.m.
Helge Bahmann wrote:
boost::atomic<long> use_count_; // #shared boost::atomic<long> weak_count_; // #weak + (#shared != 0)
wouldn't "int" do?
Yes it will. There aren't many 16 bit platforms left. :-)
I would suggest:
bool add_ref_lock() // true on success { long c = use_count_.load(memory_order_relaxed); do { if (c == 0) return false; } while(!use_count_.compare_exchange_weak(c, c+1, memory_order_relaxed)); return true; }
I have the nagging thought in my mind that the last one must be "memory_order_acquire" but I am too tired to really convince me either way :(
Relaxed is fine for add_ref. The decrements need to be acqrel. use_count() needs acquire.