157157InitProcGlobal (void )
158158{
159159PGPROC * procs ;
160- int i ;
160+ int i ,
161+ j ;
161162bool found ;
162163uint32 TotalProcs = MaxBackends + NUM_AUXILIARY_PROCS ;
163164
@@ -222,6 +223,10 @@ InitProcGlobal(void)
222223procs [i ].links .next = (SHM_QUEUE * )ProcGlobal -> autovacFreeProcs ;
223224ProcGlobal -> autovacFreeProcs = & procs [i ];
224225}
226+
227+ /* Initialize myProcLocks[] shared memory queues. */
228+ for (j = 0 ;j < NUM_LOCK_PARTITIONS ;j ++ )
229+ SHMQueueInit (& (procs [i ].myProcLocks [j ]));
225230}
226231
227232/*
@@ -243,7 +248,6 @@ InitProcess(void)
243248{
244249/* use volatile pointer to prevent code rearrangement */
245250volatile PROC_HDR * procglobal = ProcGlobal ;
246- int i ;
247251
248252/*
249253 * ProcGlobal should be set up already (if we are a backend, we inherit
@@ -303,8 +307,8 @@ InitProcess(void)
303307MarkPostmasterChildActive ();
304308
305309/*
306- * Initialize all fields of MyProc, except forthe semaphore and latch,
307- *which were prepared for us by InitProcGlobal.
310+ * Initialize all fields of MyProc, except forthose previously initialized
311+ * by InitProcGlobal.
308312 */
309313SHMQueueElemInit (& (MyProc -> links ));
310314MyProc -> waitStatus = STATUS_OK ;
@@ -326,8 +330,16 @@ InitProcess(void)
326330MyProc -> lwWaitLink = NULL ;
327331MyProc -> waitLock = NULL ;
328332MyProc -> waitProcLock = NULL ;
329- for (i = 0 ;i < NUM_LOCK_PARTITIONS ;i ++ )
330- SHMQueueInit (& (MyProc -> myProcLocks [i ]));
333+ #ifdef USE_ASSERT_CHECKING
334+ if (assert_enabled )
335+ {
336+ int i ;
337+
338+ /* Last process should have released all locks. */
339+ for (i = 0 ;i < NUM_LOCK_PARTITIONS ;i ++ )
340+ Assert (SHMQueueEmpty (& (MyProc -> myProcLocks [i ])));
341+ }
342+ #endif
331343MyProc -> recoveryConflictPending = false;
332344
333345/* Initialize fields for sync rep */
@@ -408,7 +420,6 @@ InitAuxiliaryProcess(void)
408420{
409421PGPROC * auxproc ;
410422int proctype ;
411- int i ;
412423
413424/*
414425 * ProcGlobal should be set up already (if we are a backend, we inherit
@@ -455,8 +466,8 @@ InitAuxiliaryProcess(void)
455466SpinLockRelease (ProcStructLock );
456467
457468/*
458- * Initialize all fields of MyProc, except forthe semaphore and latch,
459- *which were prepared for us by InitProcGlobal.
469+ * Initialize all fields of MyProc, except forthose previously initialized
470+ * by InitProcGlobal.
460471 */
461472SHMQueueElemInit (& (MyProc -> links ));
462473MyProc -> waitStatus = STATUS_OK ;
@@ -473,8 +484,16 @@ InitAuxiliaryProcess(void)
473484MyProc -> lwWaitLink = NULL ;
474485MyProc -> waitLock = NULL ;
475486MyProc -> waitProcLock = NULL ;
476- for (i = 0 ;i < NUM_LOCK_PARTITIONS ;i ++ )
477- SHMQueueInit (& (MyProc -> myProcLocks [i ]));
487+ #ifdef USE_ASSERT_CHECKING
488+ if (assert_enabled )
489+ {
490+ int i ;
491+
492+ /* Last process should have released all locks. */
493+ for (i = 0 ;i < NUM_LOCK_PARTITIONS ;i ++ )
494+ Assert (SHMQueueEmpty (& (MyProc -> myProcLocks [i ])));
495+ }
496+ #endif
478497
479498/*
480499 * Acquire ownership of the PGPROC's latch, so that we can use WaitLatch.
@@ -687,6 +706,17 @@ ProcKill(int code, Datum arg)
687706/* Make sure we're out of the sync rep lists */
688707SyncRepCleanupAtProcExit ();
689708
709+ #ifdef USE_ASSERT_CHECKING
710+ if (assert_enabled )
711+ {
712+ int i ;
713+
714+ /* Last process should have released all locks. */
715+ for (i = 0 ;i < NUM_LOCK_PARTITIONS ;i ++ )
716+ Assert (SHMQueueEmpty (& (MyProc -> myProcLocks [i ])));
717+ }
718+ #endif
719+
690720/*
691721 * Release any LW locks I am holding. There really shouldn't be any, but
692722 * it's cheap to check again before we cut the knees off the LWLock