mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Add barriers to the latch code.
Since their introduction latches have required barriers in SetLatch and ResetLatch - but when they were introduced there wasn't any barrier abstraction. Instead latches were documented to rely on the callsites to provide barrier semantics. Now that the barrier support looks halfway complete, add the necessary barriers to both latch implementations. Also remove a now superflous lock acquisition from syncrep.c and a superflous (and insufficient) barrier from freelist.c. There might be other cases that can now be simplified, but those are the only ones I've seen on a quick scan. We might want to backpatch this at some later point, but right now the barrier infrastructure in the backbranches isn't totally on par with master. Discussion: 20150112154026.GB2092@awork2.anarazel.de
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "portability/instr_time.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/barrier.h"
|
||||
#include "storage/latch.h"
|
||||
#include "storage/pmsignal.h"
|
||||
#include "storage/shmem.h"
|
||||
@@ -293,6 +294,13 @@ SetLatch(volatile Latch *latch)
|
||||
{
|
||||
HANDLE handle;
|
||||
|
||||
/*
|
||||
* The memory barrier has be to be placed here to ensure that any flag
|
||||
* variables possibly changed by this process have been flushed to main
|
||||
* memory, before we check/set is_set.
|
||||
*/
|
||||
pg_memory_barrier();
|
||||
|
||||
/* Quick exit if already set */
|
||||
if (latch->is_set)
|
||||
return;
|
||||
@@ -325,4 +333,12 @@ ResetLatch(volatile Latch *latch)
|
||||
Assert(latch->owner_pid == MyProcPid);
|
||||
|
||||
latch->is_set = false;
|
||||
|
||||
/*
|
||||
* Ensure that the write to is_set gets flushed to main memory before we
|
||||
* examine any flag variables. Otherwise a concurrent SetLatch might
|
||||
* falsely conclude that it needn't signal us, even though we have missed
|
||||
* seeing some flag updates that SetLatch was supposed to inform us of.
|
||||
*/
|
||||
pg_memory_barrier();
|
||||
}
|
||||
|
Reference in New Issue
Block a user