summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorRobert Haas2016-02-04 21:43:04 +0000
committerRobert Haas2016-02-04 21:43:04 +0000
commitc1772ad9225641c921545b35c84ee478c326b95e (patch)
tree879865789b951bddfe02131401c7035be44780a6 /src/include
parent5ef244a28266ce8e5666b23baed33a4c238542ff (diff)
Change the way that LWLocks for extensions are allocated.
The previous RequestAddinLWLocks() method had several disadvantages. First, the locks would be in the main tranche; we've recently decided that it's useful for LWLocks used for separate purposes to have separate tranche IDs. Second, there wasn't any correlation between what code called RequestAddinLWLocks() and what code called LWLockAssign(); when multiple modules are in use, it could become quite difficult to troubleshoot problems where LWLockAssign() ran out of locks. To fix, create a concept of named LWLock tranches which can be used either by extension or by core code. Amit Kapila and Robert Haas
Diffstat (limited to 'src/include')
-rw-r--r--src/include/pg_config_manual.h5
-rw-r--r--src/include/storage/lwlock.h22
2 files changed, 17 insertions, 10 deletions
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index 383809bf5d8..ef895211da5 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -52,11 +52,6 @@
#define SEQ_MINVALUE (-SEQ_MAXVALUE)
/*
- * Number of spare LWLocks to allocate for user-defined add-on code.
- */
-#define NUM_USER_DEFINED_LWLOCKS 4
-
-/*
* When we don't have native spinlocks, we use semaphores to simulate them.
* Decreasing this value reduces consumption of OS resources; increasing it
* may improve performance, but supplying a real spinlock implementation is
diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h
index 613df19ad64..b2bdbbaf1b9 100644
--- a/src/include/storage/lwlock.h
+++ b/src/include/storage/lwlock.h
@@ -119,6 +119,16 @@ typedef union LWLockMinimallyPadded
extern PGDLLIMPORT LWLockPadded *MainLWLockArray;
extern char *MainLWLockNames[];
+/* struct for storing named tranche information */
+typedef struct NamedLWLockTranche
+{
+ LWLockTranche lwLockTranche;
+ int trancheId;
+} NamedLWLockTranche;
+
+extern PGDLLIMPORT NamedLWLockTranche *NamedLWLockTrancheArray;
+extern PGDLLIMPORT int NamedLWLockTrancheRequests;
+
/* Names for fixed lwlocks */
#include "storage/lwlocknames.h"
@@ -178,12 +188,14 @@ extern void CreateLWLocks(void);
extern void InitLWLockAccess(void);
/*
- * The traditional method for obtaining an lwlock for use by an extension is
- * to call RequestAddinLWLocks() during postmaster startup; this will reserve
- * space for the indicated number of locks in MainLWLockArray. Subsequently,
- * a lock can be allocated using LWLockAssign.
+ * Extensions (or core code) can obtain an LWLocks by calling
+ * RequestNamedLWLockTranche() during postmaster startup. Subsequently,
+ * call GetNamedLWLockTranche() and to obtain a pointer to an array
+ * containing the number of LWLocks requested.
*/
-extern void RequestAddinLWLocks(int n);
+extern void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks);
+extern LWLockPadded *GetNamedLWLockTranche(const char *tranche_name);
+
extern LWLock *LWLockAssign(void);
/*