]> granicus.if.org Git - postgresql/blob - src/backend/storage/lmgr/single.c
Rename locking structure names to be clearer. Add narrative to
[postgresql] / src / backend / storage / lmgr / single.c
1 /*-------------------------------------------------------------------------
2  *
3  * single.c--
4  *        set single locks in the multi-level lock hierarchy
5  *
6  *        Sometimes we don't want to set all levels of the multi-level
7  *              lock hierarchy at once.  This allows us to set and release
8  *              one level at a time.  It's useful in index scans when
9  *              you can set an intent lock at the beginning and thereafter
10  *              only set page locks.  Tends to speed things up.
11  *
12  * Copyright (c) 1994, Regents of the University of California
13  *
14  *
15  * IDENTIFICATION
16  *        $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.7 1998/06/30 02:33:32 momjian Exp $
17  *
18  *-------------------------------------------------------------------------
19  */
20 #include <string.h>
21
22 #include "postgres.h"
23
24 #include "storage/lmgr.h"               /* where the declarations go */
25 #include "storage/lock.h"
26 #include "storage/multilev.h"
27 #include "utils/rel.h"
28
29 /*
30  * SingleLockReln -- lock a relation
31  *
32  * Returns: TRUE if the lock can be set, FALSE otherwise.
33  */
34 bool
35 SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action)
36 {
37         LOCKTAG         tag;
38
39         /*
40          * LOCKTAG has two bytes of padding, unfortunately.  The hash function
41          * will return miss if the padding bytes aren't zero'd.
42          */
43         MemSet(&tag, 0, sizeof(tag));
44         tag.relId = linfo->lRelId.relId;
45         tag.dbId = linfo->lRelId.dbId;
46         BlockIdSet(&(tag.tupleId.ip_blkid), InvalidBlockNumber);
47         tag.tupleId.ip_posid = InvalidOffsetNumber;
48
49         if (action == UNLOCK)
50                 return (LockRelease(MultiTableId, &tag, lockmode));
51         else
52                 return (LockAcquire(MultiTableId, &tag, lockmode));
53 }
54
55 /*
56  * SingleLockPage -- use multi-level lock table, but lock
57  *              only at the page level.
58  *
59  * Assumes that an INTENT lock has already been set in the
60  * multi-level lock table.
61  *
62  */
63 bool
64 SingleLockPage(LockInfo linfo,
65                            ItemPointer tidPtr,
66                            LOCKMODE lockmode,
67                            int action)
68 {
69         LOCKTAG         tag;
70
71         /*
72          * LOCKTAG has two bytes of padding, unfortunately.  The hash function
73          * will return miss if the padding bytes aren't zero'd.
74          */
75         MemSet(&tag, 0, sizeof(tag));
76         tag.relId = linfo->lRelId.relId;
77         tag.dbId = linfo->lRelId.dbId;
78         BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
79         tag.tupleId.ip_posid = InvalidOffsetNumber;
80
81
82         if (action == UNLOCK)
83                 return (LockRelease(MultiTableId, &tag, lockmode));
84         else
85                 return (LockAcquire(MultiTableId, &tag, lockmode));
86 }