diff options
author | Andres Freund <andres@anarazel.de> | 2015-01-13 12:58:43 +0100 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2015-01-13 12:58:43 +0100 |
commit | 14e8803f101a54d99600683543b0f893a2e3f529 (patch) | |
tree | 49ebc68f04f7905c2365d335c6e945339f4f9d51 /src/backend/port/unix_latch.c | |
parent | 4bad60e3fd9a5fc6070fd4d1bd820a280e174654 (diff) | |
download | postgresql-14e8803f101a54d99600683543b0f893a2e3f529.tar.gz postgresql-14e8803f101a54d99600683543b0f893a2e3f529.zip |
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
Diffstat (limited to 'src/backend/port/unix_latch.c')
-rw-r--r-- | src/backend/port/unix_latch.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/backend/port/unix_latch.c b/src/backend/port/unix_latch.c index 92ae7801583..147e22cee4e 100644 --- a/src/backend/port/unix_latch.c +++ b/src/backend/port/unix_latch.c @@ -51,6 +51,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" @@ -515,12 +516,11 @@ SetLatch(volatile Latch *latch) pid_t owner_pid; /* - * XXX there really ought to be a memory barrier operation right here, to - * ensure that any flag variables we might have changed get flushed to - * main memory before we check/set is_set. Without that, we have to - * require that callers provide their own synchronization for machines - * with weak memory ordering (see latch.h). + * 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) @@ -574,14 +574,12 @@ ResetLatch(volatile Latch *latch) latch->is_set = false; /* - * XXX there really ought to be a memory barrier operation right here, to - * ensure that the write to is_set gets flushed to main memory before we + * 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. - * For the moment, callers must supply their own synchronization of flag - * variables (see latch.h). */ + pg_memory_barrier(); } /* |