From 266528b553dcc128d2d38039ae821fe515ab1db1 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Mon, 9 May 2022 11:06:48 +1200
Subject: [PATCH 2/2] Add pg_test_procsignal_barrier().

A superuser-only test function to exercise the ProcSignalBarrier
mechanism.  It has no effect, other than to interrupt every process
connected to shared memory and wait for them all to acknowledge the
request.
---
 src/backend/storage/ipc/procsignal.c | 20 ++++++++++++++++++++
 src/include/catalog/pg_proc.dat      |  4 ++++
 src/include/storage/procsignal.h     |  1 +
 3 files changed, 25 insertions(+)

diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 4fe6f087db..93c31bc6b9 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -541,6 +541,10 @@ ProcessProcSignalBarrier(void)
 				type = (ProcSignalBarrierType) pg_rightmost_one_pos32(flags);
 				switch (type)
 				{
+					case PROCSIGNAL_BARRIER_TEST:
+						processed = true;		/* dummy test barrier */
+						break;
+
 					case PROCSIGNAL_BARRIER_SMGRRELEASE:
 						processed = ProcessBarrierSmgrRelease();
 						break;
@@ -679,3 +683,19 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
 
 	errno = save_errno;
 }
+
+/*
+ * A user-callable test of ProcSignalBarrier speed, that does nothing.
+ */
+Datum
+pg_test_procsignal_barrier(PG_FUNCTION_ARGS)
+{
+	if (!superuser())
+		ereport(ERROR,
+				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+				 errmsg("must be superuser")));
+
+	WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_TEST));
+
+	PG_RETURN_VOID();
+}
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 6d378ff785..434ee35364 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -6398,6 +6398,10 @@
   prorettype => 'text', proargtypes => 'text',
   prosrc => 'pg_current_logfile_1arg' },
 
+{ oid => '9777', descr => 'test ProcSignalBarrier',
+  proname => 'pg_test_procsignal_barrier', provolatile => 'v', prorettype => 'void',
+  proargtypes => '', prosrc => 'pg_test_procsignal_barrier' },
+
 { oid => '2623', descr => 'get information about file',
   proname => 'pg_stat_file', provolatile => 'v', prorettype => 'record',
   proargtypes => 'text',
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
index ee636900f3..b96d85d179 100644
--- a/src/include/storage/procsignal.h
+++ b/src/include/storage/procsignal.h
@@ -49,6 +49,7 @@ typedef enum
 
 typedef enum
 {
+	PROCSIGNAL_BARRIER_TEST,	/* empty barrier for testing */
 	PROCSIGNAL_BARRIER_SMGRRELEASE	/* ask smgr to close files */
 } ProcSignalBarrierType;
 
-- 
2.30.2

