1/*-------------------------------------------------------------------------
2 *
3 * lmgr.h
4 * POSTGRES lock manager definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/storage/lmgr.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef LMGR_H
15#define LMGR_H
16
17#include "lib/stringinfo.h"
18#include "storage/itemptr.h"
19#include "storage/lock.h"
20#include "utils/rel.h"
21
22
23/* XactLockTableWait operations */
24typedef enum XLTW_Oper
25{
26 XLTW_None,
27 XLTW_Update,
28 XLTW_Delete,
29 XLTW_Lock,
30 XLTW_LockUpdated,
31 XLTW_InsertIndex,
32 XLTW_InsertIndexUnique,
33 XLTW_FetchUpdated,
34 XLTW_RecheckExclusionConstr
35} XLTW_Oper;
36
37extern void RelationInitLockInfo(Relation relation);
38
39/* Lock a relation */
40extern void LockRelationOid(Oid relid, LOCKMODE lockmode);
41extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode);
42extern void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode);
43extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode);
44
45extern void LockRelation(Relation relation, LOCKMODE lockmode);
46extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
47extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
48extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode,
49 bool orstronger);
50extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
51
52extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
53extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
54
55/* Lock a relation for extension */
56extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
57extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
58extern bool ConditionalLockRelationForExtension(Relation relation,
59 LOCKMODE lockmode);
60extern int RelationExtensionLockWaiterCount(Relation relation);
61
62/* Lock a page (currently only used within indexes) */
63extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
64extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
65extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
66
67/* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
68extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
69extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
70 LOCKMODE lockmode);
71extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
72
73/* Lock an XID (used to wait for a transaction to finish) */
74extern void XactLockTableInsert(TransactionId xid);
75extern void XactLockTableDelete(TransactionId xid);
76extern void XactLockTableWait(TransactionId xid, Relation rel,
77 ItemPointer ctid, XLTW_Oper oper);
78extern bool ConditionalXactLockTableWait(TransactionId xid);
79
80/* Lock VXIDs, specified by conflicting locktags */
81extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress);
82extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress);
83
84/* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
85extern uint32 SpeculativeInsertionLockAcquire(TransactionId xid);
86extern void SpeculativeInsertionLockRelease(TransactionId xid);
87extern void SpeculativeInsertionWait(TransactionId xid, uint32 token);
88
89/* Lock a general object (other than a relation) of the current database */
90extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
91 LOCKMODE lockmode);
92extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
93 LOCKMODE lockmode);
94
95/* Lock a shared-across-databases object (other than a relation) */
96extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
97 LOCKMODE lockmode);
98extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
99 LOCKMODE lockmode);
100
101extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
102 LOCKMODE lockmode);
103extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
104 LOCKMODE lockmode);
105
106/* Describe a locktag for error messages */
107extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
108
109extern const char *GetLockNameFromTagType(uint16 locktag_type);
110
111#endif /* LMGR_H */
112