Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit badb83f

Browse files
committed
If we're going to have a non-panic check for held_lwlocks[] overrun,
it must occur *before* we get into the critical state of holding a lock we have no place to record. Per discussion with Qingqing Zhou.
1 parent e794dfa commit badb83f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/storage/lmgr/lwlock.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.26 2005/04/08 03:43:54 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.27 2005/04/08 14:18:35 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -213,6 +213,10 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
213213
*/
214214
Assert(!(proc == NULL && IsUnderPostmaster));
215215

216+
/* Ensure we will have room to remember the lock */
217+
if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS)
218+
elog(ERROR, "too many LWLocks taken");
219+
216220
/*
217221
* Lock out cancel/die interrupts until we exit the code section
218222
* protected by the LWLock. This ensures that interrupts will not
@@ -328,8 +332,6 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
328332
SpinLockRelease_NoHoldoff(&lock->mutex);
329333

330334
/* Add lock to list of locks held by this backend */
331-
if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS)
332-
elog(ERROR, "too many LWLocks taken");
333335
held_lwlocks[num_held_lwlocks++] = lockid;
334336

335337
/*
@@ -354,6 +356,10 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
354356

355357
PRINT_LWDEBUG("LWLockConditionalAcquire", lockid, lock);
356358

359+
/* Ensure we will have room to remember the lock */
360+
if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS)
361+
elog(ERROR, "too many LWLocks taken");
362+
357363
/*
358364
* Lock out cancel/die interrupts until we exit the code section
359365
* protected by the LWLock. This ensures that interrupts will not
@@ -398,8 +404,6 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
398404
else
399405
{
400406
/* Add lock to list of locks held by this backend */
401-
if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS)
402-
elog(ERROR, "too many LWLocks taken");
403407
held_lwlocks[num_held_lwlocks++] = lockid;
404408
}
405409

0 commit comments

Comments
 (0)