- static auto gBuckets = new EmulatedFutexBucket[kNumBuckets];
- uint64_t mixedBits = folly::hash::twang_mix64(
- reinterpret_cast<uintptr_t>(addr));
- return gBuckets[mixedBits % kNumBuckets];
+ // Statically allocating this lets us use this in allocation-sensitive
+ // contexts. This relies on the assumption that std::mutex won't dynamically
+ // allocate memory, which we assume to be the case on Linux and iOS.
+ static Indestructible<std::array<EmulatedFutexBucket, kNumBuckets>>
+ gBuckets;
+ uint64_t mixedBits =
+ folly::hash::twang_mix64(reinterpret_cast<uintptr_t>(addr));
+ return (*gBuckets)[mixedBits % kNumBuckets];