add per node mutex for emulated futex
authorNathan Bronson <ngbronson@fb.com>
Thu, 9 Oct 2014 02:44:16 +0000 (19:44 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:56:23 +0000 (17:56 -0700)
commit8961aec70edc04d3e9f43fb28cc73d084896d8e1
tree61d2f69414de1ad5b1aa35f5bde263a5fd6760eb
parentbdde233ce168266511ce333de7e092a6240a528b
add per node mutex for emulated futex

Summary:
The emulated futex (not used on Linux) has an optimization to defer
notification until after the bucket mutex has been unlocked, to avoid
lock collisions between the waiter and waker.  That code will have a
use-after-free problem if the waiter's condition_variable has a spurious
wakeup, which is allowed by the spec.  That code also doesn't do
anything about contention between multiple waiters.

This diff adds a mutex to each wait node, relieving the waiters from
having to acquire the bucket lock on wakeup.  Rather than trying to
perform a racy late notification, we just make sure to release the node
lock immediately after calling notify_one, which seems to have the
desired effect.

Test Plan:
1) existing unit tests
2) new unit tests

Reviewed By: delong.j@fb.com

Subscribers: boseant, njormrod

FB internal diff: D1602360
folly/detail/Futex.cpp
folly/test/FutexTest.cpp