15
15
* Portions Copyright (c) 1994, Regents of the University of California
16
16
*
17
17
* 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 $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -213,6 +213,10 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
213
213
*/
214
214
Assert (!(proc == NULL && IsUnderPostmaster ));
215
215
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
+
216
220
/*
217
221
* Lock out cancel/die interrupts until we exit the code section
218
222
* protected by the LWLock. This ensures that interrupts will not
@@ -328,8 +332,6 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
328
332
SpinLockRelease_NoHoldoff (& lock -> mutex );
329
333
330
334
/* 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" );
333
335
held_lwlocks [num_held_lwlocks ++ ]= lockid ;
334
336
335
337
/*
@@ -354,6 +356,10 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
354
356
355
357
PRINT_LWDEBUG ("LWLockConditionalAcquire" ,lockid ,lock );
356
358
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
+
357
363
/*
358
364
* Lock out cancel/die interrupts until we exit the code section
359
365
* protected by the LWLock. This ensures that interrupts will not
@@ -398,8 +404,6 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
398
404
else
399
405
{
400
406
/* 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" );
403
407
held_lwlocks [num_held_lwlocks ++ ]= lockid ;
404
408
}
405
409