lock.h
来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· C头文件 代码 · 共 459 行 · 第 1/2 页
H
459 行
/*------------------------------------------------------------------------- * * lock.h * POSTGRES low-level lock mechanism * * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.102 2006/11/23 05:14:04 momjian Exp $ * *------------------------------------------------------------------------- */#ifndef LOCK_H_#define LOCK_H_#include "nodes/pg_list.h"#include "storage/itemptr.h"#include "storage/lwlock.h"#include "storage/shmem.h"/* struct PGPROC is declared in proc.h, but must forward-reference it */typedef struct PGPROC PGPROC;typedef struct PROC_QUEUE{ SHM_QUEUE links; /* head of list of PGPROC objects */ int size; /* number of entries in list */} PROC_QUEUE;/* GUC variables */extern int max_locks_per_xact;#ifdef LOCK_DEBUGextern 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<<mode * corresponds to a particular lock mode). */typedef int LOCKMASK;typedef int LOCKMODE;/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */#define MAX_LOCKMODES 10#define LOCKBIT_ON(lockmode) (1 << (lockmode))#define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))/* * This data structure defines the locking semantics associated with a * "lock method". The semantics specify the meaning of each lock mode * (by defining which lock modes it conflicts with), and also whether locks * of this method are transactional (ie, are released at transaction end). * All of this data is constant and is kept in const tables. * * numLockModes -- number of lock modes (READ,WRITE,etc) that * are defined in this lock method. Must be less than MAX_LOCKMODES. * * transactional -- TRUE if locks are released automatically at xact end. * * conflictTab -- this is an array of bitmasks showing lock * mode conflicts. conflictTab[i] is a mask with the j-th bit * turned on if lock modes i and j conflict. Lock modes are * numbered 1..numLockModes; conflictTab[0] is unused. * * lockModeNames -- ID strings for debug printouts. * * trace_flag -- pointer to GUC trace flag for this lock method. */typedef struct LockMethodData{ int numLockModes; bool transactional; const LOCKMASK *conflictTab; const char *const * lockModeNames; const bool *trace_flag;} LockMethodData;typedef const LockMethodData *LockMethod;/* * Lock methods are identified by LOCKMETHODID. (Despite the declaration as * uint16, we are constrained to 256 lockmethods by the layout of LOCKTAG.) */typedef uint16 LOCKMETHODID;/* These identify the known lock methods */#define DEFAULT_LOCKMETHOD 1#define USER_LOCKMETHOD 2/* * These are the valid values of type LOCKMODE for all the standard lock * methods (both DEFAULT and USER). *//* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */#define NoLock 0#define AccessShareLock 1 /* SELECT */#define RowShareLock 2 /* SELECT FOR UPDATE/FOR SHARE */#define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */#define ShareUpdateExclusiveLock 4 /* VACUUM (non-FULL),ANALYZE, CREATE * INDEX CONCURRENTLY */#define ShareLock 5 /* CREATE INDEX (WITHOUT CONCURRENTLY) */#define ShareRowExclusiveLock 6 /* like EXCLUSIVE MODE, but allows ROW * SHARE */#define ExclusiveLock 7 /* blocks ROW SHARE/SELECT...FOR * UPDATE */#define AccessExclusiveLock 8 /* ALTER TABLE, DROP TABLE, VACUUM * FULL, and unqualified LOCK TABLE *//* * LOCKTAG is the key information needed to look up a LOCK item in the * lock hashtable. A LOCKTAG value uniquely identifies a lockable object. * * The LockTagType enum defines the different kinds of objects we can lock. * We can handle up to 256 different LockTagTypes. */typedef enum LockTagType{ LOCKTAG_RELATION, /* whole relation */ /* ID info for a relation is DB OID + REL OID; DB OID = 0 if shared */ LOCKTAG_RELATION_EXTEND, /* the right to extend a relation */ /* same ID info as RELATION */ LOCKTAG_PAGE, /* one page of a relation */ /* ID info for a page is RELATION info + BlockNumber */ LOCKTAG_TUPLE, /* one physical tuple */ /* ID info for a tuple is PAGE info + OffsetNumber */ LOCKTAG_TRANSACTION, /* transaction (for waiting for xact done) */ /* ID info for a transaction is its TransactionId */ LOCKTAG_OBJECT, /* non-relation database object */ /* ID info for an object is DB OID + CLASS OID + OBJECT OID + SUBID */ /* * Note: object ID has same representation as in pg_depend and * pg_description, but notice that we are constraining SUBID to 16 bits. * Also, we use DB OID = 0 for shared objects such as tablespaces. */ LOCKTAG_USERLOCK, /* reserved for old contrib/userlock code */ LOCKTAG_ADVISORY /* advisory user locks */} LockTagType;/* * The LOCKTAG struct is defined with malice aforethought to fit into 16 * bytes with no padding. Note that this would need adjustment if we were * to widen Oid, BlockNumber, or TransactionId to more than 32 bits. * * We include lockmethodid in the locktag so that a single hash table in * shared memory can store locks of different lockmethods. */typedef struct LOCKTAG{ uint32 locktag_field1; /* a 32-bit ID field */ uint32 locktag_field2; /* a 32-bit ID field */ uint32 locktag_field3; /* a 32-bit ID field */ uint16 locktag_field4; /* a 16-bit ID field */ uint8 locktag_type; /* see enum LockTagType */ uint8 locktag_lockmethodid; /* lockmethod indicator */} LOCKTAG;/* * These macros define how we map logical IDs of lockable objects into * the physical fields of LOCKTAG. Use these to set up LOCKTAG values, * rather than accessing the fields directly. Note multiple eval of target! */#define SET_LOCKTAG_RELATION(locktag,dboid,reloid) \ ((locktag).locktag_field1 = (dboid), \ (locktag).locktag_field2 = (reloid), \ (locktag).locktag_field3 = 0, \ (locktag).locktag_field4 = 0, \ (locktag).locktag_type = LOCKTAG_RELATION, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_RELATION_EXTEND(locktag,dboid,reloid) \ ((locktag).locktag_field1 = (dboid), \ (locktag).locktag_field2 = (reloid), \ (locktag).locktag_field3 = 0, \ (locktag).locktag_field4 = 0, \ (locktag).locktag_type = LOCKTAG_RELATION_EXTEND, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_PAGE(locktag,dboid,reloid,blocknum) \ ((locktag).locktag_field1 = (dboid), \ (locktag).locktag_field2 = (reloid), \ (locktag).locktag_field3 = (blocknum), \ (locktag).locktag_field4 = 0, \ (locktag).locktag_type = LOCKTAG_PAGE, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum) \ ((locktag).locktag_field1 = (dboid), \ (locktag).locktag_field2 = (reloid), \ (locktag).locktag_field3 = (blocknum), \ (locktag).locktag_field4 = (offnum), \ (locktag).locktag_type = LOCKTAG_TUPLE, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_TRANSACTION(locktag,xid) \ ((locktag).locktag_field1 = (xid), \ (locktag).locktag_field2 = 0, \ (locktag).locktag_field3 = 0, \ (locktag).locktag_field4 = 0, \ (locktag).locktag_type = LOCKTAG_TRANSACTION, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_OBJECT(locktag,dboid,classoid,objoid,objsubid) \ ((locktag).locktag_field1 = (dboid), \ (locktag).locktag_field2 = (classoid), \ (locktag).locktag_field3 = (objoid), \ (locktag).locktag_field4 = (objsubid), \ (locktag).locktag_type = LOCKTAG_OBJECT, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)#define SET_LOCKTAG_ADVISORY(locktag,id1,id2,id3,id4) \ ((locktag).locktag_field1 = (id1), \ (locktag).locktag_field2 = (id2), \ (locktag).locktag_field3 = (id3), \ (locktag).locktag_field4 = (id4), \ (locktag).locktag_type = LOCKTAG_ADVISORY, \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?