8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.50 2001/08/25 18:52:42 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.51 2001/09/27 16:29:12 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -145,9 +145,6 @@ LockRelation(Relation relation, LOCKMODE lockmode)
145
145
{
146
146
LOCKTAG tag ;
147
147
148
- if (LockingDisabled ())
149
- return ;
150
-
151
148
MemSet (& tag , 0 , sizeof (tag ));
152
149
tag .relId = relation -> rd_lockInfo .lockRelId .relId ;
153
150
tag .dbId = relation -> rd_lockInfo .lockRelId .dbId ;
@@ -182,9 +179,6 @@ ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
182
179
{
183
180
LOCKTAG tag ;
184
181
185
- if (LockingDisabled ())
186
- return true;
187
-
188
182
MemSet (& tag , 0 , sizeof (tag ));
189
183
tag .relId = relation -> rd_lockInfo .lockRelId .relId ;
190
184
tag .dbId = relation -> rd_lockInfo .lockRelId .dbId ;
@@ -215,9 +209,6 @@ UnlockRelation(Relation relation, LOCKMODE lockmode)
215
209
{
216
210
LOCKTAG tag ;
217
211
218
- if (LockingDisabled ())
219
- return ;
220
-
221
212
MemSet (& tag , 0 , sizeof (tag ));
222
213
tag .relId = relation -> rd_lockInfo .lockRelId .relId ;
223
214
tag .dbId = relation -> rd_lockInfo .lockRelId .dbId ;
@@ -243,9 +234,6 @@ LockRelationForSession(LockRelId *relid, LOCKMODE lockmode)
243
234
{
244
235
LOCKTAG tag ;
245
236
246
- if (LockingDisabled ())
247
- return ;
248
-
249
237
MemSet (& tag , 0 , sizeof (tag ));
250
238
tag .relId = relid -> relId ;
251
239
tag .dbId = relid -> dbId ;
@@ -264,9 +252,6 @@ UnlockRelationForSession(LockRelId *relid, LOCKMODE lockmode)
264
252
{
265
253
LOCKTAG tag ;
266
254
267
- if (LockingDisabled ())
268
- return ;
269
-
270
255
MemSet (& tag , 0 , sizeof (tag ));
271
256
tag .relId = relid -> relId ;
272
257
tag .dbId = relid -> dbId ;
@@ -277,15 +262,16 @@ UnlockRelationForSession(LockRelId *relid, LOCKMODE lockmode)
277
262
278
263
/*
279
264
* LockPage
265
+ *
266
+ * Obtain a page-level lock. This is currently used by some index access
267
+ * methods to lock index pages. For heap relations, it is used only with
268
+ * blkno == 0 to signify locking the relation for extension.
280
269
*/
281
270
void
282
271
LockPage (Relation relation , BlockNumber blkno , LOCKMODE lockmode )
283
272
{
284
273
LOCKTAG tag ;
285
274
286
- if (LockingDisabled ())
287
- return ;
288
-
289
275
MemSet (& tag , 0 , sizeof (tag ));
290
276
tag .relId = relation -> rd_lockInfo .lockRelId .relId ;
291
277
tag .dbId = relation -> rd_lockInfo .lockRelId .dbId ;
@@ -304,9 +290,6 @@ UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
304
290
{
305
291
LOCKTAG tag ;
306
292
307
- if (LockingDisabled ())
308
- return ;
309
-
310
293
MemSet (& tag , 0 , sizeof (tag ));
311
294
tag .relId = relation -> rd_lockInfo .lockRelId .relId ;
312
295
tag .dbId = relation -> rd_lockInfo .lockRelId .dbId ;
@@ -315,14 +298,21 @@ UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
315
298
LockRelease (LockTableId , & tag , GetCurrentTransactionId (), lockmode );
316
299
}
317
300
301
+ /*
302
+ * XactLockTableInsert
303
+ *
304
+ * Insert a lock showing that the given transaction ID is running ---
305
+ * this is done during xact startup. The lock can then be used to wait
306
+ * for the transaction to finish.
307
+ *
308
+ * We need no corresponding unlock function, since the lock will always
309
+ * be released implicitly at transaction commit/abort, never any other way.
310
+ */
318
311
void
319
312
XactLockTableInsert (TransactionId xid )
320
313
{
321
314
LOCKTAG tag ;
322
315
323
- if (LockingDisabled ())
324
- return ;
325
-
326
316
MemSet (& tag , 0 , sizeof (tag ));
327
317
tag .relId = XactLockTableId ;
328
318
tag .dbId = InvalidOid ; /* xids are globally unique */
@@ -333,43 +323,29 @@ XactLockTableInsert(TransactionId xid)
333
323
elog (ERROR , "XactLockTableInsert: LockAcquire failed" );
334
324
}
335
325
336
- #ifdef NOT_USED
337
- void
338
- XactLockTableDelete (TransactionId xid )
339
- {
340
- LOCKTAG tag ;
341
-
342
- if (LockingDisabled ())
343
- return ;
344
-
345
- MemSet (& tag , 0 , sizeof (tag ));
346
- tag .relId = XactLockTableId ;
347
- tag .dbId = InvalidOid ;
348
- tag .objId .xid = xid ;
349
-
350
- LockRelease (LockTableId , & tag , xid , ExclusiveLock );
351
- }
352
-
353
- #endif
354
-
326
+ /*
327
+ * XactLockTableWait
328
+ *
329
+ * Wait for the specified transaction to commit or abort.
330
+ */
355
331
void
356
332
XactLockTableWait (TransactionId xid )
357
333
{
358
334
LOCKTAG tag ;
335
+ TransactionId myxid = GetCurrentTransactionId ();
359
336
360
- if (LockingDisabled ())
361
- return ;
337
+ Assert (! TransactionIdEquals (xid , myxid ));
362
338
363
339
MemSet (& tag , 0 , sizeof (tag ));
364
340
tag .relId = XactLockTableId ;
365
341
tag .dbId = InvalidOid ;
366
342
tag .objId .xid = xid ;
367
343
368
- if (!LockAcquire (LockTableId , & tag , GetCurrentTransactionId () ,
344
+ if (!LockAcquire (LockTableId , & tag , myxid ,
369
345
ShareLock , false))
370
346
elog (ERROR , "XactLockTableWait: LockAcquire failed" );
371
347
372
- LockRelease (LockTableId , & tag , GetCurrentTransactionId () , ShareLock );
348
+ LockRelease (LockTableId , & tag , myxid , ShareLock );
373
349
374
350
/*
375
351
* Transaction was committed/aborted/crashed - we have to update
0 commit comments