Re: GetRelationPath() vs critical sections

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andy Fan <zhihuifan1213(at)163(dot)com>, pgsql-hackers(at)postgresql(dot)org, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: GetRelationPath() vs critical sections
Date: 2025-02-21 05:35:34
Message-ID: CA+hUKGJUB9M9XS+TMzB5oaFpCC+E0m1v8Gf5BN+M7k5E8zZ0PQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Feb 21, 2025 at 6:20 PM Thomas Munro <thomas(dot)munro(at)gmail(dot)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)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2025-02-21 05:47:45 Re: BgBufferSync(): clarification about reusable_buffers variable
Previous Message Tom Lane 2025-02-21 05:35:14 Re: GetRelationPath() vs critical sections