aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init/miscinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/init/miscinit.c')
-rw-r--r--src/backend/utils/init/miscinit.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 414b05e3b8c..4646e0938e9 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -39,6 +39,7 @@
#include "postmaster/postmaster.h"
#include "storage/fd.h"
#include "storage/ipc.h"
+#include "storage/latch.h"
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/procarray.h"
@@ -55,6 +56,7 @@ ProcessingMode Mode = InitProcessing;
/* List of lock files to be removed at proc exit */
static List *lock_files = NIL;
+static Latch LocalLatchData;
/* ----------------------------------------------------------------
* ignoring system indexes support stuff
@@ -189,6 +191,11 @@ InitPostmasterChild(void)
/* We don't want the postmaster's proc_exit() handlers */
on_exit_reset();
+ /* Initialize process-local latch support */
+ InitializeLatchSupport();
+ MyLatch = &LocalLatchData;
+ InitLatch(MyLatch);
+
/*
* If possible, make this process a group leader, so that the postmaster
* can signal any child processes too. Not all processes will have
@@ -215,6 +222,11 @@ InitStandaloneProcess(const char *argv0)
MyStartTime = time(NULL); /* set our start time in case we call elog */
+ /* Initialize process-local latch support */
+ InitializeLatchSupport();
+ MyLatch = &LocalLatchData;
+ InitLatch(MyLatch);
+
/* Compute paths, no postmaster to inherit from */
if (my_exec_path[0] == '\0')
{
@@ -227,6 +239,31 @@ InitStandaloneProcess(const char *argv0)
get_pkglib_path(my_exec_path, pkglib_path);
}
+void
+SwitchToSharedLatch(void)
+{
+ Assert(MyLatch == &LocalLatchData);
+ Assert(MyProc != NULL);
+
+ MyLatch = &MyProc->procLatch;
+ /*
+ * Set the shared latch as the local one might have been set. This
+ * shouldn't normally be necessary as code is supposed to check the
+ * condition before waiting for the latch, but a bit care can't hurt.
+ */
+ SetLatch(MyLatch);
+}
+
+void
+SwitchBackToLocalLatch(void)
+{
+ Assert(MyLatch != &LocalLatchData);
+ Assert(MyProc != NULL && MyLatch == &MyProc->procLatch);
+
+ MyLatch = &LocalLatchData;
+ SetLatch(MyLatch);
+}
+
/*
* GetUserId - get the current effective user ID.
*