Re: GetRelationPath() vs critical sections - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: GetRelationPath() vs critical sections
Date
Msg-id CA+hUKGJUB9M9XS+TMzB5oaFpCC+E0m1v8Gf5BN+M7k5E8zZ0PQ@mail.gmail.com
Whole thread Raw
In response to Re: GetRelationPath() vs critical sections  (Thomas Munro <thomas.munro@gmail.com>)
List pgsql-hackers
On Fri, Feb 21, 2025 at 6:20 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> #define PROCNUMBER_BITS 18
> #define MAX_BACKENDS ((1 << PROCNUMBER_BITS) - 1)
> #define PROCNUMBER_CHARS DECIMAL_DIGITS_FOR_BITS(PROCNUMBER_BITS)
>
> ... with a little helper ported to preprocessor hell from Hacker's
> Delight magic[1] for that last bit.  See attached.  But if that's a
> bit too nuts...

Erm, wait of course you just need:

#define DECIMAL_DIGITS(n) \
   ((n) < 10 ? 1 : \
    (n) < 100 ? 2 : \
    (n) < 1000 ? 3 : \
    (n) < 10000 ? 4 : \
    (n) < 100000 ? 5 : \
    (n) < 1000000 ? 6 : \
    (n) < 10000000 ? 7 : \
    (n) < 100000000 ? 8 : \
    (n) < 1000000000 ? 9 : 10)

#define PROCNUMBER_BITS 18
#define MAX_BACKENDS ((1 << PROCNUMBER_BITS) - 1)
#define PROCNUMBER_CHARS DECIMAL_DIGITS(MAX_BACKENDS)



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: GetRelationPath() vs critical sections
Next
From: Ashutosh Bapat
Date:
Subject: Re: BgBufferSync(): clarification about reusable_buffers variable