Atomically assign and set persistent rds handles
commitb772ea468062fa3cd2b52624551f0fb0f1e5aa23
authorMark Williams <mwilliams@fb.com>
Sat, 11 Nov 2017 01:00:41 +0000 (10 17:00 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Sat, 11 Nov 2017 01:14:52 +0000 (10 17:14 -0800)
tree21094fe48e347c8b9d300fabce0d8de8c8f71047
parent3fa281cd690a4808c6648b1acf88a63cafbdeee5
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
24 files changed:
hphp/runtime/base/enum-cache.h
hphp/runtime/base/rds-inl.h
hphp/runtime/base/rds.cpp
hphp/runtime/base/rds.h
hphp/runtime/base/static-string-table.cpp
hphp/runtime/base/static-string-table.h
hphp/runtime/server/cli-server.cpp
hphp/runtime/vm/class-inl.h
hphp/runtime/vm/class.cpp
hphp/runtime/vm/class.h
hphp/runtime/vm/func.cpp
hphp/runtime/vm/func.h
hphp/runtime/vm/jit/irlower-cns.cpp
hphp/runtime/vm/jit/irlower-minstr.cpp
hphp/runtime/vm/jit/target-profile.h
hphp/runtime/vm/jit/translator-runtime.cpp
hphp/runtime/vm/jit/unwind-itanium.cpp
hphp/runtime/vm/jit/vasm-prof-branch.cpp
hphp/runtime/vm/named-entity.h
hphp/runtime/vm/native.cpp
hphp/runtime/vm/native.h
hphp/runtime/vm/unit.cpp
hphp/runtime/vm/unit.h
hphp/util/smalllocks.h