summaryrefslogtreecommitdiff
path: root/src/include/storage/lmgr.h
blob: 818a2f09e59131a2f6d10f4c0323d0d26e5edf5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*-------------------------------------------------------------------------
 *
 * lmgr.h--
 *	  POSTGRES lock manager definitions.
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 * $Id: lmgr.h,v 1.13 1998/07/13 16:34:56 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */
#ifndef LMGR_H
#define LMGR_H

#include <storage/lock.h>
#include <utils/rel.h>
#include <catalog/catname.h>

/*
 * This was moved from pladt.h for the new lock manager.  Want to obsolete
 * all of the old code.
 */
typedef struct LockRelId
{
	Oid			relId;			/* a relation identifier */
	Oid			dbId;			/* a database identifier */
} LockRelId;

typedef struct LockInfoData
{
	bool		initialized;
	LockRelId	lockRelId;
	TransactionId transactionIdData;
	uint16		flags;
} LockInfoData;
typedef LockInfoData *LockInfo;

#define LockInfoIsValid(lockinfo) \
		((PointerIsValid(lockinfo)) &&  ((LockInfo) lockinfo)->initialized)

extern LockRelId VariableRelationLockRelId;
		
/*
 * RelationGetLockRelId --
 *		Returns "lock" relation identifier for a relation.
 */
/* ----------------
 * final condition is a hack to prevent problems during
 * VARIABLE relation initialization
 * ----------------
 */
#define RelationGetLockRelId(relation) \
( \
	AssertMacro(RelationIsValid(relation)), \
	(!LockInfoIsValid((LockInfo)(relation)->lockInfo)) ? \
		RelationInitLockInfo(relation) \
	: \
		(void)NULL, \
	(strcmp(RelationGetRelationName(relation)->data, \
			VariableRelationName) == 0) ? \
		VariableRelationLockRelId \
	: \
		((LockInfo)(relation)->lockInfo)->lockRelId \
)


extern Oid	LockRelIdGetRelationId(LockRelId lockRelId);
extern void RelationInitLockInfo(Relation relation);
extern void RelationSetLockForDescriptorOpen(Relation relation);
extern void RelationSetLockForRead(Relation relation);
extern void RelationUnsetLockForRead(Relation relation);
extern void RelationSetLockForWrite(Relation relation);
extern void RelationUnsetLockForWrite(Relation relation);

/* used in vaccum.c */
extern void
RelationSetLockForWritePage(Relation relation,
							ItemPointer itemPointer);

/* used in nbtpage.c, hashpage.c */
extern void
RelationSetSingleWLockPage(Relation relation,
						   ItemPointer itemPointer);
extern void
RelationUnsetSingleWLockPage(Relation relation,
							 ItemPointer itemPointer);
extern void
RelationSetSingleRLockPage(Relation relation,
						   ItemPointer itemPointer);
extern void
RelationUnsetSingleRLockPage(Relation relation,
							 ItemPointer itemPointer);
extern void RelationSetRIntentLock(Relation relation);
extern void RelationUnsetRIntentLock(Relation relation);
extern void RelationSetWIntentLock(Relation relation);
extern void RelationUnsetWIntentLock(Relation relation);

/* single.c */
extern bool SingleLockReln(LockInfo lockinfo, LOCKMODE lockmode, int action);
extern bool
SingleLockPage(LockInfo lockinfo, ItemPointer tidPtr,
			   LOCKMODE lockmode, int action);

/* proc.c */
extern void InitProcGlobal(IPCKey key);

#endif							/* LMGR_H */