#ifdef USE_INJECTION_POINTS
struct InjectionPointsCtl *ActiveInjectionPoints;
#endif
- LWLockTrancheShmemData *LWLockTranches;
- LWLockPadded *MainLWLockArray;
PROC_HDR *ProcGlobal;
PGPROC *AuxiliaryProcs;
PGPROC *PreparedXactProcs;
param->ActiveInjectionPoints = ActiveInjectionPoints;
#endif
- param->LWLockTranches = LWLockTranches;
- param->MainLWLockArray = MainLWLockArray;
param->ProcGlobal = ProcGlobal;
param->AuxiliaryProcs = AuxiliaryProcs;
param->PreparedXactProcs = PreparedXactProcs;
ActiveInjectionPoints = param->ActiveInjectionPoints;
#endif
- LWLockTranches = param->LWLockTranches;
- MainLWLockArray = param->MainLWLockArray;
ProcGlobal = param->ProcGlobal;
AuxiliaryProcs = param->AuxiliaryProcs;
PreparedXactProcs = param->PreparedXactProcs;
int num_user_defined; /* 'user_defined' entries in use */
slock_t lock; /* protects the above */
+
+ /* Size of MainLWLockArray */
+ int num_main_array_locks;
} LWLockTrancheShmemData;
-LWLockTrancheShmemData *LWLockTranches;
+static LWLockTrancheShmemData *LWLockTranches;
/* backend-local copy of NamedLWLockTranches->num_user_defined */
static int LocalNumUserDefinedTranches;
* and initialize it.
*/
void
-CreateLWLocks(void)
+LWLockShmemInit(void)
{
int numLocks;
+ bool found;
- if (!IsUnderPostmaster)
+ LWLockTranches = (LWLockTrancheShmemData *)
+ ShmemInitStruct("LWLock tranches", sizeof(LWLockTrancheShmemData), &found);
+ if (!found)
{
- /* Allocate space for LWLockTranches */
- LWLockTranches = (LWLockTrancheShmemData *)
- ShmemAlloc(sizeof(LWLockTrancheShmemData));
+ /* Calculate total number of locks needed in the main array */
+ LWLockTranches->num_main_array_locks =
+ NUM_FIXED_LWLOCKS + NumLWLocksForNamedTranches();
/* Initialize the dynamic-allocation counter for tranches */
- SpinLockInit(&LWLockTranches->lock);
LWLockTranches->num_user_defined = 0;
- /* Allocate and initialize the main array */
- numLocks = NUM_FIXED_LWLOCKS + NumLWLocksForNamedTranches();
- MainLWLockArray = (LWLockPadded *) ShmemAlloc(numLocks * sizeof(LWLockPadded));
+ SpinLockInit(&LWLockTranches->lock);
+ }
+
+ /* Allocate and initialize the main array */
+ numLocks = LWLockTranches->num_main_array_locks;
+ MainLWLockArray = (LWLockPadded *)
+ ShmemInitStruct("Main LWLock array", numLocks * sizeof(LWLockPadded), &found);
+ if (!found)
+ {
+ /* Initialize all LWLocks */
InitializeLWLocks(numLocks);
}
}
extern PGDLLIMPORT LWLockPadded *MainLWLockArray;
-/* forward declaration of private type for use only by lwlock.c */
-typedef struct LWLockTrancheShmemData LWLockTrancheShmemData;
-
-extern PGDLLIMPORT LWLockTrancheShmemData *LWLockTranches;
-
/*
* It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
* here, but we need them to figure out offsets within MainLWLockArray, and
extern void LWLockUpdateVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 val);
extern Size LWLockShmemSize(void);
-extern void CreateLWLocks(void);
+extern void LWLockShmemInit(void);
extern void InitLWLockAccess(void);
extern const char *GetLWLockIdentifier(uint32 classId, uint16 eventId);