aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2015-01-14 18:45:22 +0100
committerAndres Freund <andres@anarazel.de>2015-01-14 18:45:22 +0100
commit59f71a0d0b56b2df48db4bf1738aece5551f7a47 (patch)
tree6023eb572eade66adb21ee0ae84fd6aa33e30ac9 /src/include
parent85a2a8903f7e9151793308d0638621003aded5ae (diff)
downloadpostgresql-59f71a0d0b56b2df48db4bf1738aece5551f7a47.tar.gz
postgresql-59f71a0d0b56b2df48db4bf1738aece5551f7a47.zip
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: 20140927191243.GD5423@alap3.anarazel.de
Diffstat (limited to 'src/include')
-rw-r--r--src/include/miscadmin.h4
-rw-r--r--src/include/storage/latch.h2
2 files changed, 5 insertions, 1 deletions
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index b94a94499b7..6e33a172122 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -148,6 +148,7 @@ extern int max_worker_processes;
extern PGDLLIMPORT int MyProcPid;
extern PGDLLIMPORT pg_time_t MyStartTime;
extern PGDLLIMPORT struct Port *MyProcPort;
+extern PGDLLIMPORT struct Latch *MyLatch;
extern long MyCancelKey;
extern int MyPMChildSlot;
@@ -302,6 +303,9 @@ extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
extern void SetDataDir(const char *dir);
extern void ChangeToDataDir(void);
+extern void SwitchToSharedLatch(void);
+extern void SwitchBackToLocalLatch(void);
+
/* in utils/misc/superuser.c */
extern bool superuser(void); /* current user is superuser */
extern bool superuser_arg(Oid roleid); /* given user is superuser */
diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h
index f1577b00955..28fc684d240 100644
--- a/src/include/storage/latch.h
+++ b/src/include/storage/latch.h
@@ -85,7 +85,7 @@
* the public functions. It is defined here to allow embedding Latches as
* part of bigger structs.
*/
-typedef struct
+typedef struct Latch
{
sig_atomic_t is_set;
bool is_shared;