|
51 | 51 | #include "miscadmin.h"
|
52 | 52 | #include "portability/instr_time.h"
|
53 | 53 | #include "postmaster/postmaster.h"
|
| 54 | +#include "storage/barrier.h" |
54 | 55 | #include "storage/latch.h"
|
55 | 56 | #include "storage/pmsignal.h"
|
56 | 57 | #include "storage/shmem.h"
|
@@ -515,12 +516,11 @@ SetLatch(volatile Latch *latch)
|
515 | 516 | pid_t owner_pid;
|
516 | 517 |
|
517 | 518 | /*
|
518 |
| - * XXX there really ought to be a memory barrier operation right here, to |
519 |
| - * ensure that any flag variables we might have changed get flushed to |
520 |
| - * main memory before we check/set is_set. Without that, we have to |
521 |
| - * require that callers provide their own synchronization for machines |
522 |
| - * with weak memory ordering (see latch.h). |
| 519 | + * The memory barrier has be to be placed here to ensure that any flag |
| 520 | + * variables possibly changed by this process have been flushed to main |
| 521 | + * memory, before we check/set is_set. |
523 | 522 | */
|
| 523 | + pg_memory_barrier(); |
524 | 524 |
|
525 | 525 | /* Quick exit if already set */
|
526 | 526 | if (latch->is_set)
|
@@ -574,14 +574,12 @@ ResetLatch(volatile Latch *latch)
|
574 | 574 | latch->is_set = false;
|
575 | 575 |
|
576 | 576 | /*
|
577 |
| - * XXX there really ought to be a memory barrier operation right here, to |
578 |
| - * ensure that the write to is_set gets flushed to main memory before we |
| 577 | + * Ensure that the write to is_set gets flushed to main memory before we |
579 | 578 | * examine any flag variables. Otherwise a concurrent SetLatch might
|
580 | 579 | * falsely conclude that it needn't signal us, even though we have missed
|
581 | 580 | * seeing some flag updates that SetLatch was supposed to inform us of.
|
582 |
| - * For the moment, callers must supply their own synchronization of flag |
583 |
| - * variables (see latch.h). |
584 | 581 | */
|
| 582 | + pg_memory_barrier(); |
585 | 583 | }
|
586 | 584 |
|
587 | 585 | /*
|
|
0 commit comments