18 #error "lock.h may not be included from frontend code"
65 #define InvalidLocalTransactionId 0
66 #define LocalTransactionIdIsValid(lxid) ((lxid) != InvalidLocalTransactionId)
67 #define VirtualTransactionIdIsValid(vxid) \
68 (LocalTransactionIdIsValid((vxid).localTransactionId))
69 #define VirtualTransactionIdIsRecoveredPreparedXact(vxid) \
70 ((vxid).procNumber == INVALID_PROC_NUMBER)
71 #define VirtualTransactionIdEquals(vxid1, vxid2) \
72 ((vxid1).procNumber == (vxid2).procNumber && \
73 (vxid1).localTransactionId == (vxid2).localTransactionId)
74 #define SetInvalidVirtualTransactionId(vxid) \
75 ((vxid).procNumber = INVALID_PROC_NUMBER, \
76 (vxid).localTransactionId = InvalidLocalTransactionId)
77 #define GET_VXID_FROM_PGPROC(vxid_dst, proc) \
78 ((vxid_dst).procNumber = (proc).vxid.procNumber, \
79 (vxid_dst).localTransactionId = (proc).vxid.lxid)
82 #define MAX_LOCKMODES 10
84 #define LOCKBIT_ON(lockmode) (1 << (lockmode))
85 #define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))
125 #define DEFAULT_LOCKMETHOD 1
126 #define USER_LOCKMETHOD 2
152 #define LOCKTAG_LAST_TYPE LOCKTAG_APPLY_TRANSACTION
181 #define SET_LOCKTAG_RELATION(locktag,dboid,reloid) \
182 ((locktag).locktag_field1 = (dboid), \
183 (locktag).locktag_field2 = (reloid), \
184 (locktag).locktag_field3 = 0, \
185 (locktag).locktag_field4 = 0, \
186 (locktag).locktag_type = LOCKTAG_RELATION, \
187 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
190 #define SET_LOCKTAG_RELATION_EXTEND(locktag,dboid,reloid) \
191 ((locktag).locktag_field1 = (dboid), \
192 (locktag).locktag_field2 = (reloid), \
193 (locktag).locktag_field3 = 0, \
194 (locktag).locktag_field4 = 0, \
195 (locktag).locktag_type = LOCKTAG_RELATION_EXTEND, \
196 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
199 #define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag,dboid) \
200 ((locktag).locktag_field1 = (dboid), \
201 (locktag).locktag_field2 = 0, \
202 (locktag).locktag_field3 = 0, \
203 (locktag).locktag_field4 = 0, \
204 (locktag).locktag_type = LOCKTAG_DATABASE_FROZEN_IDS, \
205 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
208 #define SET_LOCKTAG_PAGE(locktag,dboid,reloid,blocknum) \
209 ((locktag).locktag_field1 = (dboid), \
210 (locktag).locktag_field2 = (reloid), \
211 (locktag).locktag_field3 = (blocknum), \
212 (locktag).locktag_field4 = 0, \
213 (locktag).locktag_type = LOCKTAG_PAGE, \
214 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
217 #define SET_LOCKTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum) \
218 ((locktag).locktag_field1 = (dboid), \
219 (locktag).locktag_field2 = (reloid), \
220 (locktag).locktag_field3 = (blocknum), \
221 (locktag).locktag_field4 = (offnum), \
222 (locktag).locktag_type = LOCKTAG_TUPLE, \
223 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
226 #define SET_LOCKTAG_TRANSACTION(locktag,xid) \
227 ((locktag).locktag_field1 = (xid), \
228 (locktag).locktag_field2 = 0, \
229 (locktag).locktag_field3 = 0, \
230 (locktag).locktag_field4 = 0, \
231 (locktag).locktag_type = LOCKTAG_TRANSACTION, \
232 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
235 #define SET_LOCKTAG_VIRTUALTRANSACTION(locktag,vxid) \
236 ((locktag).locktag_field1 = (vxid).procNumber, \
237 (locktag).locktag_field2 = (vxid).localTransactionId, \
238 (locktag).locktag_field3 = 0, \
239 (locktag).locktag_field4 = 0, \
240 (locktag).locktag_type = LOCKTAG_VIRTUALTRANSACTION, \
241 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
247 #define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag,xid,token) \
248 ((locktag).locktag_field1 = (xid), \
249 (locktag).locktag_field2 = (token), \
250 (locktag).locktag_field3 = 0, \
251 (locktag).locktag_field4 = 0, \
252 (locktag).locktag_type = LOCKTAG_SPECULATIVE_TOKEN, \
253 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
262 #define SET_LOCKTAG_OBJECT(locktag,dboid,classoid,objoid,objsubid) \
263 ((locktag).locktag_field1 = (dboid), \
264 (locktag).locktag_field2 = (classoid), \
265 (locktag).locktag_field3 = (objoid), \
266 (locktag).locktag_field4 = (objsubid), \
267 (locktag).locktag_type = LOCKTAG_OBJECT, \
268 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
270 #define SET_LOCKTAG_ADVISORY(locktag,id1,id2,id3,id4) \
271 ((locktag).locktag_field1 = (id1), \
272 (locktag).locktag_field2 = (id2), \
273 (locktag).locktag_field3 = (id3), \
274 (locktag).locktag_field4 = (id4), \
275 (locktag).locktag_type = LOCKTAG_ADVISORY, \
276 (locktag).locktag_lockmethodid = USER_LOCKMETHOD)
282 #define SET_LOCKTAG_APPLY_TRANSACTION(locktag,dboid,suboid,xid,objid) \
283 ((locktag).locktag_field1 = (dboid), \
284 (locktag).locktag_field2 = (suboid), \
285 (locktag).locktag_field3 = (xid), \
286 (locktag).locktag_field4 = (objid), \
287 (locktag).locktag_type = LOCKTAG_APPLY_TRANSACTION, \
288 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
324 #define LOCK_LOCKMETHOD(lock) ((LOCKMETHODID) (lock).tag.locktag_lockmethodid)
325 #define LOCK_LOCKTAG(lock) ((LockTagType) (lock).tag.locktag_type)
382 #define PROCLOCK_LOCKMETHOD(proclock) \
383 LOCK_LOCKMETHOD(*((proclock).tag.myLock))
443 #define LOCALLOCK_LOCKMETHOD(llock) ((llock).tag.lock.locktag_lockmethodid)
444 #define LOCALLOCK_LOCKTAG(llock) ((LockTagType) (llock).tag.lock.locktag_type)
524 #define LockHashPartition(hashcode) \
525 ((hashcode) % NUM_LOCK_PARTITIONS)
526 #define LockHashPartitionLock(hashcode) \
527 (&MainLWLockArray[LOCK_MANAGER_LWLOCK_OFFSET + \
528 LockHashPartition(hashcode)].lock)
529 #define LockHashPartitionLockByIndex(i) \
530 (&MainLWLockArray[LOCK_MANAGER_LWLOCK_OFFSET + (i)].lock)
541 #define LockHashPartitionLockByProc(leader_pgproc) \
542 LockHashPartitionLock(GetNumberFromPGProc(leader_pgproc))
562 bool reportMemoryError,
567 LOCKMODE lockmode,
bool sessionLock);
573 LOCKMODE lockmode,
bool orstronger);
574 #ifdef USE_ASSERT_CHECKING
575 extern HTAB *GetLockMethodLocalHash(
void);
578 LOCKMODE lockmode,
bool sessionLock);
616 extern void DumpLocks(
PGPROC *proc);
617 extern void DumpAllLocks(
void);
#define pg_attribute_noreturn()
uint32 LocalTransactionId
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
PGDLLIMPORT int max_locks_per_xact
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
struct LOCALLOCK LOCALLOCK
const LockMethodData * LockMethod
void VirtualXactLockTableInsert(VirtualTransactionId vxid)
PGPROC * GetBlockingAutoVacuumPgproc(void)
xl_standby_lock * GetRunningTransactionLocks(int *nlocks)
@ LOCKTAG_RELATION_EXTEND
@ LOCKTAG_SPECULATIVE_TOKEN
@ LOCKTAG_APPLY_TRANSACTION
@ LOCKTAG_DATABASE_FROZEN_IDS
@ LOCKTAG_VIRTUALTRANSACTION
void GrantAwaitedLock(void)
int LockWaiterCount(const LOCKTAG *locktag)
void AtPrepare_Locks(void)
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
void lock_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Size LockManagerShmemSize(void)
void RememberSimpleDeadLock(PGPROC *proc1, LOCKMODE lockmode, LOCK *lock, PGPROC *proc2)
struct LOCALLOCKOWNER LOCALLOCKOWNER
void InitLockManagerAccess(void)
void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
void VirtualXactLockTableCleanup(void)
BlockedProcsData * GetBlockerStatusData(int blocked_pid)
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
void RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
struct LockMethodData LockMethodData
void LockReassignCurrentOwner(LOCALLOCK **locallocks, int nlocks)
struct BlockedProcData BlockedProcData
LockData * GetLockStatusData(void)
void AbortStrongLockAcquire(void)
@ DS_BLOCKED_BY_AUTOVACUUM
struct LockInstanceData LockInstanceData
void LockManagerShmemInit(void)
void lock_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
struct PROCLOCKTAG PROCLOCKTAG
PGDLLIMPORT const char *const LockTagTypeNames[]
void lock_twophase_standby_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
void InitDeadLockChecking(void)
void LockReleaseCurrentOwner(LOCALLOCK **locallocks, int nlocks)
void lock_twophase_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
void LockReleaseSession(LOCKMETHODID lockmethodid)
void MarkLockClear(LOCALLOCK *locallock)
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
DeadLockState DeadLockCheck(PGPROC *proc)
void DeadLockReport(void) pg_attribute_noreturn()
uint32 LockTagHashCode(const LOCKTAG *locktag)
bool LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock)
struct LOCALLOCKTAG LOCALLOCKTAG
LockMethod GetLocksMethodTable(const LOCK *lock)
void PostPrepare_Locks(TransactionId xid)
@ LOCKACQUIRE_ALREADY_CLEAR
@ LOCKACQUIRE_ALREADY_HELD
struct BlockedProcsData BlockedProcsData
LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)
static PgChecksumMode mode
struct ResourceOwnerData * owner
LOCALLOCKOWNER * lockOwners
bool holdsStrongLockCount
uint8 locktag_lockmethodid
int requested[MAX_LOCKMODES]
int granted[MAX_LOCKMODES]
VirtualTransactionId vxid
const LOCKMASK * conflictTab
const char *const * lockModeNames
LocalTransactionId localTransactionId