aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/procsignal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/ipc/procsignal.c')
-rw-r--r--src/backend/storage/ipc/procsignal.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index f1c8ff8f9e4..d158bb7a19f 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -80,13 +80,6 @@ typedef struct
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER];
} ProcSignalHeader;
-/*
- * We reserve a slot for each possible BackendId, plus one for each
- * possible auxiliary process type. (This scheme assumes there is not
- * more than one of any auxiliary process type at a time.)
- */
-#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
-
/* Check whether the relevant type bit is set in the flags. */
#define BARRIER_SHOULD_CHECK(flags, type) \
(((flags) & (((uint32) 1) << (uint32) (type))) != 0)
@@ -102,6 +95,20 @@ static bool CheckProcSignal(ProcSignalReason reason);
static void CleanupProcSignalState(int status, Datum arg);
static void ResetProcSignalBarrierBits(uint32 flags);
static bool ProcessBarrierPlaceholder(void);
+static inline int GetNumProcSignalSlots(void);
+
+/*
+ * GetNumProcSignalSlots
+ *
+ * We reserve a slot for each possible BackendId, plus one for each possible
+ * auxiliary process type. (This scheme assume there is not more than one of
+ * any auxiliary process type at a time.)
+ */
+static inline int
+GetNumProcSignalSlots(void)
+{
+ return GetMaxBackends() + NUM_AUXPROCTYPES;
+}
/*
* ProcSignalShmemSize
@@ -112,7 +119,7 @@ ProcSignalShmemSize(void)
{
Size size;
- size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
+ size = mul_size(GetNumProcSignalSlots(), sizeof(ProcSignalSlot));
size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
return size;
}
@@ -126,6 +133,7 @@ ProcSignalShmemInit(void)
{
Size size = ProcSignalShmemSize();
bool found;
+ int numProcSignalSlots = GetNumProcSignalSlots();
ProcSignal = (ProcSignalHeader *)
ShmemInitStruct("ProcSignal", size, &found);
@@ -137,7 +145,7 @@ ProcSignalShmemInit(void)
pg_atomic_init_u64(&ProcSignal->psh_barrierGeneration, 0);
- for (i = 0; i < NumProcSignalSlots; ++i)
+ for (i = 0; i < numProcSignalSlots; ++i)
{
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
@@ -163,7 +171,7 @@ ProcSignalInit(int pss_idx)
ProcSignalSlot *slot;
uint64 barrier_generation;
- Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
+ Assert(pss_idx >= 1 && pss_idx <= GetNumProcSignalSlots());
slot = &ProcSignal->psh_slot[pss_idx - 1];
@@ -292,7 +300,7 @@ SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
*/
int i;
- for (i = NumProcSignalSlots - 1; i >= 0; i--)
+ for (i = GetNumProcSignalSlots() - 1; i >= 0; i--)
{
slot = &ProcSignal->psh_slot[i];
@@ -333,6 +341,7 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
{
uint32 flagbit = 1 << (uint32) type;
uint64 generation;
+ int numProcSignalSlots = GetNumProcSignalSlots();
/*
* Set all the flags.
@@ -342,7 +351,7 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
* anything that we do afterwards. (This is also true of the later call to
* pg_atomic_add_fetch_u64.)
*/
- for (int i = 0; i < NumProcSignalSlots; i++)
+ for (int i = 0; i < numProcSignalSlots; i++)
{
volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
@@ -368,7 +377,7 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
* backends that need to update state - but they won't actually need to
* change any state.
*/
- for (int i = NumProcSignalSlots - 1; i >= 0; i--)
+ for (int i = numProcSignalSlots - 1; i >= 0; i--)
{
volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
pid_t pid = slot->pss_pid;
@@ -393,7 +402,7 @@ WaitForProcSignalBarrier(uint64 generation)
{
Assert(generation <= pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration));
- for (int i = NumProcSignalSlots - 1; i >= 0; i--)
+ for (int i = GetNumProcSignalSlots() - 1; i >= 0; i--)
{
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
uint64 oldval;