Atomically assign and set persistent rds handles
Summary:
In some cases, we have a globally visible handle (eg in the NamedEntity table). If we bind the handle (which happens atomically), there will still be a brief period where other threads can see that the handle is bound, but the handle's value has not yet been set; and if we bind a temporary handle, set the value at the handle, and then update the global handle, we would need a lock to prevent multiple threads from allocating and initializing the space for the same object (wasting space in rds). Using a single lock would cause threads to block unnecessarily, and using lots of locks could be wasteful.
This changes the condition for "unbound" from equal-to-zero to less-than-or-equal-to-zero, and uses futexes to implement light weight locks in the rds handles themselves, and a callback in bind which does the allocation, and any initialization.
Reviewed By: alexeyt
Differential Revision:
D6269104
fbshipit-source-id:
78af86352ae2f1b70494be8f3923f9b946309476