ConcurrentHashMap
authorDave Watson <davejwatson@fb.com>
Wed, 26 Jul 2017 16:41:45 +0000 (09:41 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 26 Jul 2017 16:51:34 +0000 (09:51 -0700)
commitf0b5826b141bd91fae906a2c6721ab77e667c859
tree6220398d9b03ddb265826f23878da669ea8b9e08
parent763b84fbc36895d3b6f1da10979fb050a399133f
ConcurrentHashMap

Summary:
A ConcurrentHashMap with wait-free readers, as in Java's ConcurrentHashMap.

It's a pretty generic closed-addressing chaining hashtable, except find() uses two hazard pointers
to do hand-over-hand traversal of the list, so it never takes a lock.

On rehash, only the part of the chain that remains the same (i.e. is still hashed to the same bucket)
is reused, otherwise we have to allocate new nodes.

Reallocating nodes means we either have to copy the value_type, or add in an extra indirection
to access it.  Both are supported.

There's still a couple opportunities to squeeze some more perf out with optimistic loading
of nodes / cachelines, but I didn't go that far yet, it sill looks pretty good.

Reviewed By: davidtgoldblatt

Differential Revision: D5349966

fbshipit-source-id: 022e8adacd0ddd32b2a4563caa99c0c4878851d8
folly/concurrency/ConcurrentHashMap.h [new file with mode: 0644]
folly/concurrency/detail/ConcurrentHashMap-detail.h [new file with mode: 0644]
folly/concurrency/test/ConcurrentHashMapTest.cpp [new file with mode: 0644]
folly/experimental/hazptr/hazptr-impl.h