summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorAndres Freund2015-01-14 17:45:22 +0000
committerAndres Freund2015-01-14 17:45:22 +0000
commit59f71a0d0b56b2df48db4bf1738aece5551f7a47 (patch)
tree6023eb572eade66adb21ee0ae84fd6aa33e30ac9 /src/backend/storage/ipc
parent85a2a8903f7e9151793308d0638621003aded5ae (diff)
Add a default local latch for use in signal handlers.
To do so, move InitializeLatchSupport() into the new common process initialization functions, and add a new global variable MyLatch. MyLatch is usable as soon InitPostmasterChild() has been called (i.e. very early during startup). Initially it points to a process local latch that exists in all processes. InitProcess/InitAuxiliaryProcess then replaces that local latch with PGPROC->procLatch. During shutdown the reverse happens. This is primarily advantageous for two reasons: For one it simplifies dealing with the shared process latch, especially in signal handlers, because instead of having to check for MyProc, MyLatch can be used unconditionally. For another, a later patch that makes FEs/BE communication use latches, now can rely on the existence of a latch, even before having gone through InitProcess. Discussion: [email protected]
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/procsignal.c4
-rw-r--r--src/backend/storage/ipc/shm_mq.c12
2 files changed, 8 insertions, 8 deletions
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index cf094187661..48573bef60b 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -292,8 +292,8 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
- if (set_latch_on_sigusr1 && MyProc != NULL)
- SetLatch(&MyProc->procLatch);
+ if (set_latch_on_sigusr1)
+ SetLatch(MyLatch);
latch_sigusr1_handler();
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 7c41400d216..d42a8d1ae4d 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -827,13 +827,13 @@ shm_mq_send_bytes(shm_mq_handle *mqh, Size nbytes, const void *data,
* at top of loop, because setting an already-set latch is much
* cheaper than setting one that has been reset.
*/
- WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
+ WaitLatch(MyLatch, WL_LATCH_SET, 0);
/* An interrupt may have occurred while we were waiting. */
CHECK_FOR_INTERRUPTS();
/* Reset the latch so we don't spin. */
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
}
else
{
@@ -924,13 +924,13 @@ shm_mq_receive_bytes(shm_mq *mq, Size bytes_needed, bool nowait,
* loop, because setting an already-set latch is much cheaper than
* setting one that has been reset.
*/
- WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
+ WaitLatch(MyLatch, WL_LATCH_SET, 0);
/* An interrupt may have occurred while we were waiting. */
CHECK_FOR_INTERRUPTS();
/* Reset the latch so we don't spin. */
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
}
}
@@ -991,13 +991,13 @@ shm_mq_wait_internal(volatile shm_mq *mq, PGPROC *volatile * ptr,
}
/* Wait to be signalled. */
- WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
+ WaitLatch(MyLatch, WL_LATCH_SET, 0);
/* An interrupt may have occurred while we were waiting. */
CHECK_FOR_INTERRUPTS();
/* Reset the latch so we don't spin. */
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
}
}
PG_CATCH();