Re: unconstify equivalent for volatile

Andres Freund <andres@anarazel.de>

From: Andres Freund <andres@anarazel.de>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2019-02-18T20:25:11Z
Lists: pgsql-hackers
Hi,

On 2019-02-18 16:39:25 +0100, Peter Eisentraut wrote:
> diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c
> index 7da337d11f..fa7d72ef76 100644
> --- a/src/backend/storage/ipc/latch.c
> +++ b/src/backend/storage/ipc/latch.c
> @@ -381,7 +381,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
>  
>  	if (wakeEvents & WL_LATCH_SET)
>  		AddWaitEventToSet(set, WL_LATCH_SET, PGINVALID_SOCKET,
> -						  (Latch *) latch, NULL);
> +						  unvolatize(Latch *, latch), NULL);
>  
>  	/* Postmaster-managed callers must handle postmaster death somehow. */
>  	Assert(!IsUnderPostmaster ||

ISTM this one should rather be solved by removing all volatiles from
latch.[ch]. As that's a cross-process concern we can't rely on it
anyway (and have placed barriers a few years back to allay concerns /
bugs due to reordering).


> diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c
> index d707993bf6..48f4311464 100644
> --- a/src/backend/storage/ipc/pmsignal.c
> +++ b/src/backend/storage/ipc/pmsignal.c
> @@ -134,7 +134,7 @@ PMSignalShmemInit(void)
>  
>  	if (!found)
>  	{
> -		MemSet(PMSignalState, 0, PMSignalShmemSize());
> +		MemSet(unvolatize(PMSignalData *, PMSignalState), 0, PMSignalShmemSize());
>  		PMSignalState->num_child_flags = MaxLivePostmasterChildren();
>  	}
>  }

Same.  Did you put an type assertion into MemSet(), or how did you
discover this one as needing to be changed?

.oO(We really ought to remove MemSet()).


Commits

  1. Add macro to cast away volatile without allowing changes to underlying type

  2. Initialize structure at declaration