Skip to content

Commit 496d5d5

Browse files
committed
Fix custom_signal patch and callback declaration in accordance with it
1 parent 62ccdd1 commit 496d5d5

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

patches/custom_signals_12.0.patch

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
From 44e4d28abd0a63a6e1c4a75c55ad27fb827dbfa4 Mon Sep 17 00:00:00 2001
2-
From: Alexey Kondratov <[email protected]>
3-
Date: Fri, 18 Oct 2019 19:44:01 +0300
4-
Subject: [PATCH] [custom_signals] Allow extensions to set custom signal
5-
handlers
6-
7-
---
8-
src/backend/storage/ipc/procsignal.c | 94 ++++++++++++++++++++++++++++
9-
src/backend/tcop/postgres.c | 2 +
10-
src/include/storage/procsignal.h | 19 ++++++
11-
3 files changed, 115 insertions(+)
12-
131
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
14-
index 7605b2c3674..0802ed1119b 100644
2+
index 7605b2c367..6a4327fe76 100644
153
--- a/src/backend/storage/ipc/procsignal.c
164
+++ b/src/backend/storage/ipc/procsignal.c
175
@@ -60,12 +60,20 @@ typedef struct
@@ -72,7 +60,7 @@ index 7605b2c3674..0802ed1119b 100644
7260
/*
7361
* SendProcSignal
7462
* Send a signal to a Postgres process
75-
@@ -292,9 +330,65 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
63+
@@ -292,9 +330,63 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
7664
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
7765
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
7866

@@ -127,19 +115,17 @@ index 7605b2c3674..0802ed1119b 100644
127115
+ if (CustomSignalPendings[i])
128116
+ {
129117
+ ProcSignalHandler_type handler;
130-
+ ProcSignalReason reason;
131118
+
132119
+ CustomSignalPendings[i] = false;
133120
+ handler = CustomInterruptHandlers[i];
134-
+ reason = PROCSIG_CUSTOM_1 + i;
135121
+ if (handler != NULL)
136-
+ handler(reason);
122+
+ handler();
137123
+ }
138124
+
139125
+ RESUME_INTERRUPTS();
140126
+}
141127
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
142-
index c28cc370129..f5a48b98e86 100644
128+
index c28cc37012..f5a48b98e8 100644
143129
--- a/src/backend/tcop/postgres.c
144130
+++ b/src/backend/tcop/postgres.c
145131
@@ -3139,6 +3139,8 @@ ProcessInterrupts(void)
@@ -152,7 +138,7 @@ index c28cc370129..f5a48b98e86 100644
152138

153139

154140
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
155-
index 05b186a05c2..84290d60975 100644
141+
index 05b186a05c..d961790b7e 100644
156142
--- a/src/include/storage/procsignal.h
157143
+++ b/src/include/storage/procsignal.h
158144
@@ -17,6 +17,8 @@
@@ -189,7 +175,7 @@ index 05b186a05c2..84290d60975 100644
189175
} ProcSignalReason;
190176

191177
+/* Handler of custom process signal */
192-
+typedef void (*ProcSignalHandler_type) (ProcSignalReason reason);
178+
+typedef void (*ProcSignalHandler_type) (void);
193179
+
194180
/*
195181
* prototypes for functions in procsignal.c
@@ -208,6 +194,3 @@ index 05b186a05c2..84290d60975 100644
208194
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
209195

210196
#endif /* PROCSIGNAL_H */
211-
--
212-
2.17.1
213-

pg_query_state.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ typedef struct
8888
Latch *caller;
8989
} RemoteUserIdResult;
9090

91-
static void SendCurrentUserId(ProcSignalReason);
92-
static void SendBgWorkerPids(ProcSignalReason);
91+
static void SendCurrentUserId(void);
92+
static void SendBgWorkerPids(void);
9393
static Oid GetRemoteBackendUserId(PGPROC *proc);
9494
static List *GetRemoteBackendWorkers(PGPROC *proc);
9595
static List *GetRemoteBackendQueryStates(PGPROC *leader,
@@ -662,7 +662,7 @@ pg_query_state(PG_FUNCTION_ARGS)
662662
}
663663

664664
static void
665-
SendCurrentUserId(ProcSignalReason reason)
665+
SendCurrentUserId(void)
666666
{
667667
SpinLockAcquire(&counterpart_userid->mutex);
668668
counterpart_userid->userid = GetUserId();
@@ -704,6 +704,8 @@ GetRemoteBackendUserId(PGPROC *proc)
704704

705705
#if PG_VERSION_NUM < 100000
706706
WaitLatch(MyLatch, WL_LATCH_SET, 0);
707+
#elif PG_VERSION_NUM < 120000
708+
WaitLatch(MyLatch, WL_LATCH_SET, 0, PG_WAIT_EXTENSION);
707709
#else
708710
WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
709711
PG_WAIT_EXTENSION);
@@ -746,6 +748,10 @@ shm_mq_receive_with_timeout(shm_mq_handle *mqh,
746748

747749
#if PG_VERSION_NUM < 100000
748750
rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT, delay);
751+
#elif PG_VERSION_NUM < 120000
752+
rc = WaitLatch(MyLatch,
753+
WL_LATCH_SET | WL_TIMEOUT,
754+
delay, PG_WAIT_EXTENSION);
749755
#else
750756
rc = WaitLatch(MyLatch,
751757
WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT,
@@ -805,7 +811,7 @@ typedef struct
805811
} BgWorkerPids;
806812

807813
static void
808-
SendBgWorkerPids(ProcSignalReason reason)
814+
SendBgWorkerPids(void)
809815
{
810816
ListCell *iter;
811817
List *all_workers = NIL;

pg_query_state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ extern pg_qs_params *params;
6868
extern shm_mq *mq;
6969

7070
/* signal_handler.c */
71-
extern void SendQueryState(ProcSignalReason);
71+
extern void SendQueryState(void);
7272

7373
#endif

signal_handler.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ serialize_stack(char *dest, List *qs_stack)
154154
* This function is called when fire custom signal QueryStatePollReason
155155
*/
156156
void
157-
SendQueryState(ProcSignalReason reason)
157+
SendQueryState(void)
158158
{
159159
shm_mq_handle *mqh;
160160

@@ -166,6 +166,8 @@ SendQueryState(ProcSignalReason reason)
166166

167167
#if PG_VERSION_NUM < 100000
168168
WaitLatch(MyLatch, WL_LATCH_SET, 0);
169+
#elif PG_VERSION_NUM < 120000
170+
WaitLatch(MyLatch, WL_LATCH_SET, 0, PG_WAIT_IPC);
169171
#else
170172
WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0, PG_WAIT_IPC);
171173
#endif

0 commit comments

Comments
 (0)