Re: Atomic operations within spinlocks

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Atomic operations within spinlocks
Date: 2020-06-10 13:51:13
Message-ID: 2297028.1591797073@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Fri, Jun 5, 2020 at 8:19 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
>> Randomly noticed while looking at the code:
>> uint64 flagbit = UINT64CONST(1) << (uint64) type;
>>
>> that shouldn't be 64bit, right?

> I'm going to admit ignorance here. What's the proper coding rule?

The shift distance can't exceed 64, so there's no need for it to be
wider than int. "type" is an enum, so explicitly casting it to an
integral type seems like good practice, but int is sufficient.

ISTR older compilers insisting that the shift distance not be
wider than int. But C99 doesn't seem to require that -- it only
restricts the value of the right operand.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Li Japin 2020-06-10 13:53:12 Re: Terminate the idle sessions
Previous Message Amit Kapila 2020-06-10 13:24:23 Re: Parallel Seq Scan vs kernel read ahead