]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | // This source code is licensed under both the GPLv2 (found in the | |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
5 | ||
6 | #include <folly/synchronization/ParkingLot.h> | |
7 | ||
8 | #include <array> | |
9 | ||
10 | namespace folly { | |
11 | namespace parking_lot_detail { | |
12 | ||
13 | Bucket& Bucket::bucketFor(uint64_t key) { | |
14 | constexpr size_t const kNumBuckets = 4096; | |
15 | ||
16 | // Statically allocating this lets us use this in allocation-sensitive | |
17 | // contexts. This relies on the assumption that std::mutex won't dynamically | |
18 | // allocate memory, which we assume to be the case on Linux and iOS. | |
19 | static Indestructible<std::array<Bucket, kNumBuckets>> gBuckets; | |
20 | return (*gBuckets)[key % kNumBuckets]; | |
21 | } | |
22 | ||
23 | std::atomic<uint64_t> idallocator{0}; | |
24 | ||
25 | } // namespace parking_lot_detail | |
26 | } // namespace folly |