Fix some memory_order parameters in AtomicHashMap
authorJordan DeLong <jdelong@fb.com>
Sun, 3 Jun 2012 21:58:50 +0000 (14:58 -0700)
committerAndrew Gallagher <agallagher@fb.com>
Tue, 5 Jun 2012 23:21:05 +0000 (16:21 -0700)
commit8eda5c6b51581591d3c219f2b4b1b50811801280
treea32d4f4c458e9589a0fd61222bd98a032ca9f5fb
parent1534e22469d10969c2321113b83de0e02891d00b
Fix some memory_order parameters in AtomicHashMap

Summary: Herb Sutter noticed an error in the AHM find pseudo-code at
the C++ conference, and the error is in the real implementation too.
We should be using memory_order_acquire, because we need the load of
the key to happen before any subsequent loads of the value itself.
Our implementation is conservative for a memory_order_relaxed load
(we generate the same code as if it were memory_order_acquire---i.e. a
compiler barrier but no memory barriers), so this should not change the
generated code.  Correctness is a good idea, though (when we upgrade
to gcc 4.7's atomics it might not be as conservative).  Also, erase was
doing three loads when one is enough.  ... also fixes an exception safety
bug in insert.  (Phew.)

Test Plan: Ran the AHM unit tests, debug and opt.

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D485744
folly/AtomicHashArray-inl.h
folly/AtomicHashArray.h