/*------------------------------------------------------------------------- * * lock.h * POSTGRES low-level lock mechanism * * * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.80 2004/08/26 17:22:28 tgl Exp $ * *------------------------------------------------------------------------- */ #ifndef LOCK_H_ #define LOCK_H_ #include "storage/itemptr.h" #include "storage/lwlock.h" #include "storage/shmem.h" /* originally in procq.h */ typedef struct PROC_QUEUE { SHM_QUEUE links; /* head of list of PGPROC objects */ int size; /* number of entries in list */ } PROC_QUEUE; /* struct PGPROC is declared in proc.h, but must forward-reference it */ typedef struct PGPROC PGPROC; /* GUC variables */ extern int max_locks_per_xact; #ifdef LOCK_DEBUG extern int Trace_lock_oidmin; extern bool Trace_locks; extern bool Trace_userlocks; extern int Trace_lock_table; extern bool Debug_deadlocks; #endif /* LOCK_DEBUG */ /* * LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit * mask indicating a set of held or requested lock types (the bit 1<tag.lockmethodid) /* * This struct holds information passed from lmgr internals to the lock * listing user-level functions (lockfuncs.c). For each PROCLOCK in the * system, the SHMEM_OFFSET, PROCLOCK itself, and associated PGPROC and * LOCK objects are stored. (Note there will often be multiple copies * of the same PGPROC or LOCK.) We do not store the SHMEM_OFFSET of the * PGPROC or LOCK separately, since they're in the PROCLOCK's tag fields. */ typedef struct { int nelements; /* The length of each of the arrays */ SHMEM_OFFSET *proclockaddrs; PROCLOCK *proclocks; PGPROC *procs; LOCK *locks; } LockData; extern int NumLockMethods; /* * function prototypes */ extern void InitLocks(void); extern LockMethod GetLocksMethodTable(LOCK *lock); extern LOCKMETHODID LockMethodTableInit(const char *tabName, const LOCKMASK *conflictsP, int numModes, int maxBackends); extern LOCKMETHODID LockMethodTableRename(LOCKMETHODID lockmethodid); extern bool LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, TransactionId xid, LOCKMODE lockmode, bool dontWait); extern bool LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, TransactionId xid, LOCKMODE lockmode); extern bool LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc, bool allxids); extern int LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock, PGPROC *proc, int *myHolding); extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode); extern void RemoveFromWaitQueue(PGPROC *proc); extern int LockShmemSize(int maxBackends); extern bool DeadLockCheck(PGPROC *proc); extern void DeadLockReport(void); extern void RememberSimpleDeadLock(PGPROC *proc1, LOCKMODE lockmode, LOCK *lock, PGPROC *proc2); extern void InitDeadLockChecking(void); extern LockData *GetLockStatusData(void); extern const char *GetLockmodeName(LOCKMODE mode); #ifdef LOCK_DEBUG extern void DumpLocks(void); extern void DumpAllLocks(void); #endif #endif /* LOCK_H */