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/0803:43:54 tgl Exp $
18+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.27 2005/04/0814:18:35 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -213,6 +213,10 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
213213 */
214214Assert (!(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)
328332SpinLockRelease_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" );
333335held_lwlocks [num_held_lwlocks ++ ]= lockid ;
334336
335337/*
@@ -354,6 +356,10 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
354356
355357PRINT_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)
398404else
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" );
403407held_lwlocks [num_held_lwlocks ++ ]= lockid ;
404408}
405409