From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | Peter Geoghegan <peter(at)2ndquadrant(dot)com> |
Cc: | Daniel Farina <daniel(at)heroku(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Is this non-volatile pointer access OK? |
Date: | 2012-09-04 01:21:11 |
Message-ID: | 1346721671.30124.7.camel@vanquo.pezone.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, 2012-09-03 at 11:14 +0100, Peter Geoghegan wrote:
> Come to think of it, the whole convention of using a lower-case
> variant of the original pointer variable name seems like a foot-gun,
> given the harmful and indeed very subtle consequences of making this
> error.
With some inventive macro magic, you could probably make this safer.
I'm thinking something along the lines of replacing
SpinLockAcquire(&xlogctl->info_lck);
with
SpinLockAcquire(XLogCtl, info_lck);
which expands to
{
volatile typeof(XLogCtl) *XLogCtl_volatile = XLogCtl;
void *XLogCtl = NULL; // compiler error or crash at run time if used
OldSpinLockAcquire(XLogCtl_volatile->info_lock);
...
and then something corresponding for SpinLockRelease.
This will likely only work with modern compilers, but it could give you
some amount of static checking against this problem.
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2012-09-04 02:22:58 | Re: Yet another failure mode in pg_upgrade |
Previous Message | Craig Ringer | 2012-09-04 01:01:41 | Re: Reduce the time to know trigger_file's existence |