Commit 2a2352e0 authored by Tom Lane's avatar Tom Lane

Replace memcpy() calls in xlog.c critical sections with struct assignments.

This gets rid of a dangerous-looking use of the not-volatile XLogCtl
pointer in a couple of spinlock-protected sections, where the normal
coding rule is that you should only access shared memory through a
pointer-to-volatile.  I think the risk is only hypothetical not actual,
since for there to be a bug the compiler would have to move the spinlock
acquire or release across the memcpy() call, which one sincerely hopes
it will not.  Still, it looks cleaner this way.

Per comment from Daniel Farina and subsequent discussion.
parent 6259678f
...@@ -8158,8 +8158,8 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) ...@@ -8158,8 +8158,8 @@ RecoveryRestartPoint(const CheckPoint *checkPoint)
* work out the next time it wants to perform a restartpoint. * work out the next time it wants to perform a restartpoint.
*/ */
SpinLockAcquire(&xlogctl->info_lck); SpinLockAcquire(&xlogctl->info_lck);
XLogCtl->lastCheckPointRecPtr = ReadRecPtr; xlogctl->lastCheckPointRecPtr = ReadRecPtr;
memcpy(&XLogCtl->lastCheckPoint, checkPoint, sizeof(CheckPoint)); xlogctl->lastCheckPoint = *checkPoint;
SpinLockRelease(&xlogctl->info_lck); SpinLockRelease(&xlogctl->info_lck);
} }
...@@ -8194,7 +8194,7 @@ CreateRestartPoint(int flags) ...@@ -8194,7 +8194,7 @@ CreateRestartPoint(int flags)
/* Get a local copy of the last safe checkpoint record. */ /* Get a local copy of the last safe checkpoint record. */
SpinLockAcquire(&xlogctl->info_lck); SpinLockAcquire(&xlogctl->info_lck);
lastCheckPointRecPtr = xlogctl->lastCheckPointRecPtr; lastCheckPointRecPtr = xlogctl->lastCheckPointRecPtr;
memcpy(&lastCheckPoint, &XLogCtl->lastCheckPoint, sizeof(CheckPoint)); lastCheckPoint = xlogctl->lastCheckPoint;
SpinLockRelease(&xlogctl->info_lck); SpinLockRelease(&xlogctl->info_lck);
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment