]> granicus.if.org Git - postgresql/blob - src/include/storage/proc.h
Standard pgindent run for 8.1.
[postgresql] / src / include / storage / proc.h
1 /*-------------------------------------------------------------------------
2  *
3  * proc.h
4  *        per-process shared memory data structures
5  *
6  *
7  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.84 2005/10/15 02:49:46 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef _PROC_H_
15 #define _PROC_H_
16
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19 #include "storage/pg_sema.h"
20
21
22 /*
23  * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
24  * for non-aborted subtransactions of its current top transaction.      These
25  * have to be treated as running XIDs by other backends.
26  *
27  * We also keep track of whether the cache overflowed (ie, the transaction has
28  * generated at least one subtransaction that didn't fit in the cache).
29  * If none of the caches have overflowed, we can assume that an XID that's not
30  * listed anywhere in the PGPROC array is not a running transaction.  Else we
31  * have to look at pg_subtrans.
32  */
33 #define PGPROC_MAX_CACHED_SUBXIDS 64    /* XXX guessed-at value */
34
35 struct XidCache
36 {
37         bool            overflowed;
38         int                     nxids;
39         TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
40 };
41
42 /*
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.
45  *
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.
49  *
50  * Note: twophase.c also sets up a dummy PGPROC struct for each currently
51  * prepared transaction.  These PGPROCs appear in the ProcArray data structure
52  * so that the prepared transactions appear to be still running and are
53  * correctly shown as holding locks.  A prepared transaction PGPROC can be
54  * distinguished from a real one at need by the fact that it has pid == 0.
55  * The semaphore and lock-related fields in a prepared-xact PGPROC are unused.
56  */
57 struct PGPROC
58 {
59         /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
60         SHM_QUEUE       links;                  /* list link if process is in a list */
61
62         PGSemaphoreData sem;            /* ONE semaphore to sleep on */
63         int                     waitStatus;             /* STATUS_OK or STATUS_ERROR after wakeup */
64
65         TransactionId xid;                      /* transaction currently being executed by
66                                                                  * this proc */
67
68         TransactionId xmin;                     /* minimal running XID as it was when we were
69                                                                  * starting our xact: vacuum must not remove
70                                                                  * tuples deleted by xid >= xmin ! */
71
72         int                     pid;                    /* This backend's process id, or 0 */
73         Oid                     databaseId;             /* OID of database this backend is using */
74         Oid                     roleId;                 /* OID of role using this backend */
75
76         /* Info about LWLock the process is currently waiting for, if any. */
77         bool            lwWaiting;              /* true if waiting for an LW lock */
78         bool            lwExclusive;    /* true if waiting for exclusive access */
79         struct PGPROC *lwWaitLink;      /* next waiter for same LW lock */
80
81         /* Info about lock the process is currently waiting for, if any. */
82         /* waitLock and waitProcLock are NULL if not currently waiting. */
83         LOCK       *waitLock;           /* Lock object we're sleeping on ... */
84         PROCLOCK   *waitProcLock;       /* Per-holder info for awaited lock */
85         LOCKMODE        waitLockMode;   /* type of lock we're waiting for */
86         LOCKMASK        heldLocks;              /* bitmask for lock types already held on this
87                                                                  * lock object by this backend */
88
89         SHM_QUEUE       procLocks;              /* list of PROCLOCK objects for locks held or
90                                                                  * awaited by this backend */
91
92         struct XidCache subxids;        /* cache for subtransaction XIDs */
93 };
94
95 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
96
97
98 extern DLLIMPORT PGPROC *MyProc;
99
100
101 /*
102  * There is one ProcGlobal struct for the whole installation.
103  */
104 typedef struct PROC_HDR
105 {
106         /* Head of list of free PGPROC structures */
107         SHMEM_OFFSET freeProcs;
108         /* Current shared estimate of appropriate spins_per_delay value */
109         int                     spins_per_delay;
110 } PROC_HDR;
111
112
113 #define DUMMY_PROC_DEFAULT      0
114 #define DUMMY_PROC_BGWRITER 1
115 #define NUM_DUMMY_PROCS         2
116
117
118 /* configurable options */
119 extern int      DeadlockTimeout;
120 extern int      StatementTimeout;
121
122 extern volatile bool cancel_from_timeout;
123
124
125 /*
126  * Function Prototypes
127  */
128 extern int      ProcGlobalSemas(void);
129 extern Size ProcGlobalShmemSize(void);
130 extern void InitProcGlobal(void);
131 extern void InitProcess(void);
132 extern void InitDummyProcess(int proctype);
133 extern bool HaveNFreeProcs(int n);
134 extern void ProcReleaseLocks(bool isCommit);
135
136 extern void ProcQueueInit(PROC_QUEUE *queue);
137 extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
138                   LOCK *lock, PROCLOCK *proclock);
139 extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
140 extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
141 extern bool LockWaitCancel(void);
142
143 extern void ProcWaitForSignal(void);
144 extern void ProcCancelWaitForSignal(void);
145 extern void ProcSendSignal(int pid);
146
147 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
148 extern bool disable_sig_alarm(bool is_statement_timeout);
149 extern void handle_sig_alarm(SIGNAL_ARGS);
150
151 #endif   /* PROC_H */