Fix build for 32-bit pointersnightly-2022.10.28
authorJames Tyne <[email protected]>
Fri, 28 Oct 2022 02:16:46 +0000 (27 19:16 -0700)
committerFacebook GitHub Bot <[email protected]>
Fri, 28 Oct 2022 02:16:46 +0000 (27 19:16 -0700)
Summary: Removes the assumption that `uintptr_t` is 64 bits. Instead of hardcoding 52 bits for local IDs, the allocation is now 52 bits when `uintptr_t` is 64 bits and 26 bits when `uintptr_t` is 32 bits.

Reviewed By: roddym

Differential Revision: D40687166

fbshipit-source-id: 3eb9cf9a3a99ffb74f4871504d73fcecc26c91a2

third-party/thrift/src/thrift/lib/cpp2/server/RequestsRegistry.cpp

index d34edf1..7d94914 100644 (file)
@@ -26,10 +26,11 @@ namespace thrift {
 namespace {
 // RequestId storage.
 // Reserve some high bits for future use. Currently the maximum id supported
-// is 10^52, so thrift servers theoretically can generate unique request id
-// for ~12 years, assuming the QPS is ~10 million.
-const size_t kLsbBits = 52;
-const uintptr_t kLsbMask = (1ull << kLsbBits) - 1;
+// is 2^52 (on 64-bit systems), so thrift servers theoretically can generate
+// unique request id for ~12 years, assuming the QPS is ~10 million.
+constexpr size_t kReserveBits = sizeof(uintptr_t) >= 8 ? 12 : 6;
+constexpr size_t kLsbBits = 8 * sizeof(uintptr_t) - kReserveBits;
+constexpr uintptr_t kLsbMask = (1ull << kLsbBits) - 1;
 
 struct RegistryIdManager {
  public:
@@ -41,7 +42,7 @@ struct RegistryIdManager {
     }
 
     auto id = nextId_++;
-    CHECK(id < 4096);
+    CHECK_LT(id, 1ull << kReserveBits); // 4096, if pointers are 64 bits
     return id;
   }