Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2891b4

Browse files
committed
Initialize myProcLocks queues just once, at postmaster startup.
In assert-enabled builds, we assert during the shutdown sequence thatthe queues have been properly emptied, and during process startup thatwe are inheriting empty queues. In non-assert enabled builds, we justsave a few cycles.
1 parent391af9f commitc2891b4

File tree

1 file changed

+41
-11
lines changed
  • src/backend/storage/lmgr

1 file changed

+41
-11
lines changed

‎src/backend/storage/lmgr/proc.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ void
157157
InitProcGlobal(void)
158158
{
159159
PGPROC*procs;
160-
inti;
160+
inti,
161+
j;
161162
boolfound;
162163
uint32TotalProcs=MaxBackends+NUM_AUXILIARY_PROCS;
163164

@@ -222,6 +223,10 @@ InitProcGlobal(void)
222223
procs[i].links.next= (SHM_QUEUE*)ProcGlobal->autovacFreeProcs;
223224
ProcGlobal->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 */
245250
volatilePROC_HDR*procglobal=ProcGlobal;
246-
inti;
247251

248252
/*
249253
* ProcGlobal should be set up already (if we are a backend, we inherit
@@ -303,8 +307,8 @@ InitProcess(void)
303307
MarkPostmasterChildActive();
304308

305309
/*
306-
* Initialize all fields of MyProc, except forthe semaphore and latch,
307-
*which were prepared for usby InitProcGlobal.
310+
* Initialize all fields of MyProc, except forthose previously initialized
311+
* by InitProcGlobal.
308312
*/
309313
SHMQueueElemInit(&(MyProc->links));
310314
MyProc->waitStatus=STATUS_OK;
@@ -326,8 +330,16 @@ InitProcess(void)
326330
MyProc->lwWaitLink=NULL;
327331
MyProc->waitLock=NULL;
328332
MyProc->waitProcLock=NULL;
329-
for (i=0;i<NUM_LOCK_PARTITIONS;i++)
330-
SHMQueueInit(&(MyProc->myProcLocks[i]));
333+
#ifdefUSE_ASSERT_CHECKING
334+
if (assert_enabled)
335+
{
336+
inti;
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
331343
MyProc->recoveryConflictPending= false;
332344

333345
/* Initialize fields for sync rep */
@@ -408,7 +420,6 @@ InitAuxiliaryProcess(void)
408420
{
409421
PGPROC*auxproc;
410422
intproctype;
411-
inti;
412423

413424
/*
414425
* ProcGlobal should be set up already (if we are a backend, we inherit
@@ -455,8 +466,8 @@ InitAuxiliaryProcess(void)
455466
SpinLockRelease(ProcStructLock);
456467

457468
/*
458-
* Initialize all fields of MyProc, except forthe semaphore and latch,
459-
*which were prepared for usby InitProcGlobal.
469+
* Initialize all fields of MyProc, except forthose previously initialized
470+
* by InitProcGlobal.
460471
*/
461472
SHMQueueElemInit(&(MyProc->links));
462473
MyProc->waitStatus=STATUS_OK;
@@ -473,8 +484,16 @@ InitAuxiliaryProcess(void)
473484
MyProc->lwWaitLink=NULL;
474485
MyProc->waitLock=NULL;
475486
MyProc->waitProcLock=NULL;
476-
for (i=0;i<NUM_LOCK_PARTITIONS;i++)
477-
SHMQueueInit(&(MyProc->myProcLocks[i]));
487+
#ifdefUSE_ASSERT_CHECKING
488+
if (assert_enabled)
489+
{
490+
inti;
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 */
688707
SyncRepCleanupAtProcExit();
689708

709+
#ifdefUSE_ASSERT_CHECKING
710+
if (assert_enabled)
711+
{
712+
inti;
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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp