Commit c2891b46 authored by Robert Haas's avatar Robert Haas

Initialize myProcLocks queues just once, at postmaster startup.

In assert-enabled builds, we assert during the shutdown sequence that
the queues have been properly emptied, and during process startup that
we are inheriting empty queues.  In non-assert enabled builds, we just
save a few cycles.
parent 391af9f7
...@@ -157,7 +157,8 @@ void ...@@ -157,7 +157,8 @@ void
InitProcGlobal(void) InitProcGlobal(void)
{ {
PGPROC *procs; PGPROC *procs;
int i; int i,
j;
bool found; bool found;
uint32 TotalProcs = MaxBackends + NUM_AUXILIARY_PROCS; uint32 TotalProcs = MaxBackends + NUM_AUXILIARY_PROCS;
...@@ -222,6 +223,10 @@ InitProcGlobal(void) ...@@ -222,6 +223,10 @@ InitProcGlobal(void)
procs[i].links.next = (SHM_QUEUE *) ProcGlobal->autovacFreeProcs; procs[i].links.next = (SHM_QUEUE *) ProcGlobal->autovacFreeProcs;
ProcGlobal->autovacFreeProcs = &procs[i]; ProcGlobal->autovacFreeProcs = &procs[i];
} }
/* Initialize myProcLocks[] shared memory queues. */
for (j = 0; j < NUM_LOCK_PARTITIONS; j++)
SHMQueueInit(&(procs[i].myProcLocks[j]));
} }
/* /*
...@@ -243,7 +248,6 @@ InitProcess(void) ...@@ -243,7 +248,6 @@ InitProcess(void)
{ {
/* use volatile pointer to prevent code rearrangement */ /* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal; volatile PROC_HDR *procglobal = ProcGlobal;
int i;
/* /*
* ProcGlobal should be set up already (if we are a backend, we inherit * ProcGlobal should be set up already (if we are a backend, we inherit
...@@ -303,8 +307,8 @@ InitProcess(void) ...@@ -303,8 +307,8 @@ InitProcess(void)
MarkPostmasterChildActive(); MarkPostmasterChildActive();
/* /*
* Initialize all fields of MyProc, except for the semaphore and latch, * Initialize all fields of MyProc, except for those previously initialized
* which were prepared for us by InitProcGlobal. * by InitProcGlobal.
*/ */
SHMQueueElemInit(&(MyProc->links)); SHMQueueElemInit(&(MyProc->links));
MyProc->waitStatus = STATUS_OK; MyProc->waitStatus = STATUS_OK;
...@@ -326,8 +330,16 @@ InitProcess(void) ...@@ -326,8 +330,16 @@ InitProcess(void)
MyProc->lwWaitLink = NULL; MyProc->lwWaitLink = NULL;
MyProc->waitLock = NULL; MyProc->waitLock = NULL;
MyProc->waitProcLock = NULL; MyProc->waitProcLock = NULL;
for (i = 0; i < NUM_LOCK_PARTITIONS; i++) #ifdef USE_ASSERT_CHECKING
SHMQueueInit(&(MyProc->myProcLocks[i])); if (assert_enabled)
{
int i;
/* Last process should have released all locks. */
for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
Assert(SHMQueueEmpty(&(MyProc->myProcLocks[i])));
}
#endif
MyProc->recoveryConflictPending = false; MyProc->recoveryConflictPending = false;
/* Initialize fields for sync rep */ /* Initialize fields for sync rep */
...@@ -408,7 +420,6 @@ InitAuxiliaryProcess(void) ...@@ -408,7 +420,6 @@ InitAuxiliaryProcess(void)
{ {
PGPROC *auxproc; PGPROC *auxproc;
int proctype; int proctype;
int i;
/* /*
* ProcGlobal should be set up already (if we are a backend, we inherit * ProcGlobal should be set up already (if we are a backend, we inherit
...@@ -455,8 +466,8 @@ InitAuxiliaryProcess(void) ...@@ -455,8 +466,8 @@ InitAuxiliaryProcess(void)
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
/* /*
* Initialize all fields of MyProc, except for the semaphore and latch, * Initialize all fields of MyProc, except for those previously initialized
* which were prepared for us by InitProcGlobal. * by InitProcGlobal.
*/ */
SHMQueueElemInit(&(MyProc->links)); SHMQueueElemInit(&(MyProc->links));
MyProc->waitStatus = STATUS_OK; MyProc->waitStatus = STATUS_OK;
...@@ -473,8 +484,16 @@ InitAuxiliaryProcess(void) ...@@ -473,8 +484,16 @@ InitAuxiliaryProcess(void)
MyProc->lwWaitLink = NULL; MyProc->lwWaitLink = NULL;
MyProc->waitLock = NULL; MyProc->waitLock = NULL;
MyProc->waitProcLock = NULL; MyProc->waitProcLock = NULL;
for (i = 0; i < NUM_LOCK_PARTITIONS; i++) #ifdef USE_ASSERT_CHECKING
SHMQueueInit(&(MyProc->myProcLocks[i])); if (assert_enabled)
{
int i;
/* Last process should have released all locks. */
for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
Assert(SHMQueueEmpty(&(MyProc->myProcLocks[i])));
}
#endif
/* /*
* Acquire ownership of the PGPROC's latch, so that we can use WaitLatch. * Acquire ownership of the PGPROC's latch, so that we can use WaitLatch.
...@@ -687,6 +706,17 @@ ProcKill(int code, Datum arg) ...@@ -687,6 +706,17 @@ ProcKill(int code, Datum arg)
/* Make sure we're out of the sync rep lists */ /* Make sure we're out of the sync rep lists */
SyncRepCleanupAtProcExit(); SyncRepCleanupAtProcExit();
#ifdef USE_ASSERT_CHECKING
if (assert_enabled)
{
int i;
/* Last process should have released all locks. */
for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
Assert(SHMQueueEmpty(&(MyProc->myProcLocks[i])));
}
#endif
/* /*
* Release any LW locks I am holding. There really shouldn't be any, but * Release any LW locks I am holding. There really shouldn't be any, but
* it's cheap to check again before we cut the knees off the LWLock * it's cheap to check again before we cut the knees off the LWLock
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment