Re: GetRelationPath() vs critical sections
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andy Fan <zhihuifan1213@163.com>, pgsql-hackers@postgresql.org, Noah Misch <noah@leadboat.com>, Michael Paquier <michael.paquier@gmail.com>
Date: 2025-02-21T05:35:34Z
Lists: 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)
Commits
-
Change _mdfd_segpath() to return paths by value
- ecbff4378bee 18.0 landed
-
Change relpath() et al to return path by value
- 37c87e63f9e1 18.0 landed