1 /*-------------------------------------------------------------------------
4 * per-process shared memory data structures
7 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.73 2004/08/27 17:07:42 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/backendid.h"
19 #include "storage/lock.h"
20 #include "storage/pg_sema.h"
24 * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
25 * for non-aborted subtransactions of its current top transaction. These
26 * have to be treated as running XIDs by other backends.
28 * We also keep track of whether the cache overflowed (ie, the transaction has
29 * generated at least one subtransaction that didn't fit in the cache).
30 * If none of the caches have overflowed, we can assume that an XID that's not
31 * listed anywhere in the PGPROC array is not a running transaction. Else we
32 * have to look at pg_subtrans.
34 #define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */
39 TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
43 * Each backend has a PGPROC struct in shared memory. There is also a list of
44 * currently-unused PGPROC structs that will be reallocated to new backends.
46 * links: list link for any list the PGPROC is in. When waiting for a lock,
47 * the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC
48 * is linked into ProcGlobal's freeProcs list.
52 /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
53 SHM_QUEUE links; /* list link if process is in a list */
55 PGSemaphoreData sem; /* ONE semaphore to sleep on */
56 int waitStatus; /* STATUS_OK or STATUS_ERROR after wakeup */
58 TransactionId xid; /* transaction currently being executed by
61 TransactionId xmin; /* minimal running XID as it was when we
62 * were starting our xact: vacuum must not
63 * remove tuples deleted by xid >= xmin ! */
65 int pid; /* This backend's process id */
66 Oid databaseId; /* OID of database this backend is using */
69 * XLOG location of first XLOG record written by this backend's
70 * current transaction. If backend is not in a transaction or hasn't
71 * yet modified anything, logRec.xrecoff is zero.
75 /* Info about LWLock the process is currently waiting for, if any. */
76 bool lwWaiting; /* true if waiting for an LW lock */
77 bool lwExclusive; /* true if waiting for exclusive access */
78 struct PGPROC *lwWaitLink; /* next waiter for same LW lock */
80 /* Info about lock the process is currently waiting for, if any. */
81 /* waitLock and waitProcLock are NULL if not currently waiting. */
82 LOCK *waitLock; /* Lock object we're sleeping on ... */
83 PROCLOCK *waitProcLock; /* Per-holder info for awaited lock */
84 LOCKMODE waitLockMode; /* type of lock we're waiting for */
85 LOCKMASK heldLocks; /* bitmask for lock types already held on
86 * this lock object by this backend */
88 SHM_QUEUE procLocks; /* list of PROCLOCK objects for locks held
89 * or awaited by this backend */
91 struct XidCache subxids; /* cache for subtransaction XIDs */
94 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
97 extern DLLIMPORT PGPROC *MyProc;
101 * There is one ProcGlobal struct for the whole installation.
103 typedef struct PROC_HDR
105 /* Head of list of free PGPROC structures */
106 SHMEM_OFFSET freeProcs;
110 #define DUMMY_PROC_DEFAULT 0
111 #define DUMMY_PROC_BGWRITER 1
112 #define NUM_DUMMY_PROCS 2
115 /* configurable options */
116 extern int DeadlockTimeout;
117 extern int StatementTimeout;
121 * Function Prototypes
123 extern int ProcGlobalSemas(int maxBackends);
124 extern void InitProcGlobal(int maxBackends);
125 extern void InitProcess(void);
126 extern void InitDummyProcess(int proctype);
127 extern void ProcReleaseLocks(bool isCommit);
129 extern void ProcQueueInit(PROC_QUEUE *queue);
130 extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
131 LOCK *lock, PROCLOCK *proclock);
132 extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
133 extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
134 extern bool LockWaitCancel(void);
136 extern void ProcWaitForSignal(void);
137 extern void ProcCancelWaitForSignal(void);
138 extern void ProcSendSignal(BackendId procId);
140 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
141 extern bool disable_sig_alarm(bool is_statement_timeout);
142 extern void handle_sig_alarm(SIGNAL_ARGS);