Commit 1145acc7 authored by Andres Freund's avatar Andres Freund

Add a barrier primitive for synchronizing backends.

Provide support for dynamic or static parties of processes to wait for
all processes to reach point in the code before continuing.

This is similar to the mechanism of the same name in POSIX threads and
MPI, though has explicit phasing and dynamic party support like the
Java core library's Phaser.

This will be used by an upcoming patch adding support for parallel
hash joins.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=2_y7oi01OjA_wLvYcWMc9_d=LaoxrY3eiROCZkB_qakA@mail.gmail.com
parent fa330f9a
...@@ -8,7 +8,7 @@ subdir = src/backend/storage/ipc ...@@ -8,7 +8,7 @@ subdir = src/backend/storage/ipc
top_builddir = ../../../.. top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
OBJS = dsm_impl.o dsm.o ipc.o ipci.o latch.o pmsignal.o procarray.o \ OBJS = barrier.o dsm_impl.o dsm.o ipc.o ipci.o latch.o pmsignal.o procarray.o \
procsignal.o shmem.o shmqueue.o shm_mq.o shm_toc.o sinval.o \ procsignal.o shmem.o shmqueue.o shm_mq.o shm_toc.o sinval.o \
sinvaladt.o standby.o sinvaladt.o standby.o
......
This diff is collapsed.
/*-------------------------------------------------------------------------
*
* barrier.h
* Barriers for synchronizing cooperating processes.
*
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/storage/barrier.h
*
*-------------------------------------------------------------------------
*/
#ifndef BARRIER_H
#define BARRIER_H
/*
* For the header previously known as "barrier.h", please include
* "port/atomics.h", which deals with atomics, compiler barriers and memory
* barriers.
*/
#include "storage/condition_variable.h"
#include "storage/spin.h"
typedef struct Barrier
{
slock_t mutex;
int phase; /* phase counter */
int participants; /* the number of participants attached */
int arrived; /* the number of participants that have
* arrived */
int elected; /* highest phase elected */
bool static_party; /* used only for assertions */
ConditionVariable condition_variable;
} Barrier;
extern void BarrierInit(Barrier *barrier, int num_workers);
extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info);
extern bool BarrierArriveAndDetach(Barrier *barrier);
extern int BarrierAttach(Barrier *barrier);
extern bool BarrierDetach(Barrier *barrier);
extern int BarrierPhase(Barrier *barrier);
extern int BarrierParticipants(Barrier *barrier);
#endif /* BARRIER_H */
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