Remove volatiles from {procarray,volatile}.c and fix memory ordering issue.
authorAndres Freund <andres@anarazel.de>
Sat, 10 Nov 2018 04:54:40 +0000 (20:54 -0800)
committerAndres Freund <andres@anarazel.de>
Sun, 11 Nov 2018 00:11:57 +0000 (16:11 -0800)
commit450c7defa6d5f3c9fdb6efc92cca106c7b582cb3
tree5c8e97cf2c2bfdd0fabf5e4dc709b953c5450108
parent69ee2ff9308bbfe0e0a89667555e901fec5e154b
Remove volatiles from {procarray,volatile}.c and fix memory ordering issue.

The use of volatiles in procarray.c largely originated from the time
when postgres did not have reliable compiler and memory
barriers. That's not the case anymore, so we can do better.

Several of the functions in procarray.c can be bottlenecks, and
removal of volatile yields mildly better code.

The new state, with explicit memory barriers, is also more
correct. The previous use of volatile did not actually deliver
sufficient guarantees on weakly ordered machines, in particular the
logic in GetNewTransactionId() does not look safe.  It seems unlikely
to be a problem in practice, but worth fixing.

Thomas and I independently wrote a patch for this.

Reported-By: Andres Freund and Thomas Munro
Author: Andres Freund, with cherrypicked changes from a patch by Thomas Munro
Discussion:
    https://postgr.es/m/20181005172955.wyjb4fzcdzqtaxjq@alap3.anarazel.de
    https://postgr.es/m/CAEepm=1nff0x=7i3YQO16jLA2qw-F9O39YmUew4oq-xcBQBs0g@mail.gmail.com
src/backend/access/transam/varsup.c
src/backend/storage/ipc/procarray.c