1 /*-------------------------------------------------------------------------
4 * per-process shared memory data structures
7 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: proc.h,v 1.60 2002/09/04 20:31:45 momjian 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 has a PGPROC struct in shared memory. There is also a list of
25 * currently-unused PGPROC structs that will be reallocated to new backends.
27 * links: list link for any list the PGPROC is in. When waiting for a lock,
28 * the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC
29 * is linked into ProcGlobal's freeProcs list.
33 /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
34 SHM_QUEUE links; /* list link if process is in a list */
36 PGSemaphoreData sem; /* ONE semaphore to sleep on */
37 int errType; /* STATUS_OK or STATUS_ERROR after wakeup */
39 TransactionId xid; /* transaction currently being executed by
42 TransactionId xmin; /* minimal running XID as it was when we
43 * were starting our xact: vacuum must not
44 * remove tuples deleted by xid >= xmin ! */
46 int pid; /* This backend's process id */
47 Oid databaseId; /* OID of database this backend is using */
50 * XLOG location of first XLOG record written by this backend's
51 * current transaction. If backend is not in a transaction or hasn't
52 * yet modified anything, logRec.xrecoff is zero.
56 /* Info about LWLock the process is currently waiting for, if any. */
57 bool lwWaiting; /* true if waiting for an LW lock */
58 bool lwExclusive; /* true if waiting for exclusive access */
59 struct PGPROC *lwWaitLink; /* next waiter for same LW lock */
61 /* Info about lock the process is currently waiting for, if any. */
62 /* waitLock and waitHolder are NULL if not currently waiting. */
63 LOCK *waitLock; /* Lock object we're sleeping on ... */
64 PROCLOCK *waitHolder; /* Per-holder info for awaited lock */
65 LOCKMODE waitLockMode; /* type of lock we're waiting for */
66 LOCKMASK heldLocks; /* bitmask for lock types already held on
67 * this lock object by this backend */
69 SHM_QUEUE procHolders; /* list of PROCLOCK objects for locks held
70 * or awaited by this backend */
73 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
76 extern PGPROC *MyProc;
80 * There is one ProcGlobal struct for the whole installation.
82 typedef struct PROC_HDR
84 /* Head of list of free PGPROC structures */
85 SHMEM_OFFSET freeProcs;
89 /* configurable option */
90 extern int DeadlockTimeout;
96 extern int ProcGlobalSemas(int maxBackends);
97 extern void InitProcGlobal(int maxBackends);
98 extern void InitProcess(void);
99 extern void InitDummyProcess(void);
100 extern void ProcReleaseLocks(bool isCommit);
102 extern void ProcQueueInit(PROC_QUEUE *queue);
103 extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
104 LOCK *lock, PROCLOCK *holder);
105 extern PGPROC *ProcWakeup(PGPROC *proc, int errType);
106 extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
107 extern bool LockWaitCancel(void);
108 extern void CheckDeadLock(void);
110 extern void ProcWaitForSignal(void);
111 extern void ProcCancelWaitForSignal(void);
112 extern void ProcSendSignal(BackendId procId);
114 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
115 extern bool disable_sig_alarm(bool is_statement_timeout);
116 extern void handle_sig_alarm(SIGNAL_ARGS);