OSDN Git Service

pgindent run.
[pg-rex/syncrep.git] / src / include / storage / proc.h
1 /*-------------------------------------------------------------------------
2  *
3  * proc.h
4  *        per-process shared memory data structures
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: proc.h,v 1.60 2002/09/04 20:31:45 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef _PROC_H_
15 #define _PROC_H_
16
17 #include "access/xlog.h"
18 #include "storage/backendid.h"
19 #include "storage/lock.h"
20 #include "storage/pg_sema.h"
21
22
23 /*
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.
26  *
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.
30  */
31 struct PGPROC
32 {
33         /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
34         SHM_QUEUE       links;                  /* list link if process is in a list */
35
36         PGSemaphoreData sem;            /* ONE semaphore to sleep on */
37         int                     errType;                /* STATUS_OK or STATUS_ERROR after wakeup */
38
39         TransactionId xid;                      /* transaction currently being executed by
40                                                                  * this proc */
41
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 ! */
45
46         int                     pid;                    /* This backend's process id */
47         Oid                     databaseId;             /* OID of database this backend is using */
48
49         /*
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.
53          */
54         XLogRecPtr      logRec;
55
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 */
60
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 */
68
69         SHM_QUEUE       procHolders;    /* list of PROCLOCK objects for locks held
70                                                                  * or awaited by this backend */
71 };
72
73 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
74
75
76 extern PGPROC *MyProc;
77
78
79 /*
80  * There is one ProcGlobal struct for the whole installation.
81  */
82 typedef struct PROC_HDR
83 {
84         /* Head of list of free PGPROC structures */
85         SHMEM_OFFSET freeProcs;
86 } PROC_HDR;
87
88
89 /* configurable option */
90 extern int      DeadlockTimeout;
91
92
93 /*
94  * Function Prototypes
95  */
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);
101
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);
109
110 extern void ProcWaitForSignal(void);
111 extern void ProcCancelWaitForSignal(void);
112 extern void ProcSendSignal(BackendId procId);
113
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);
117
118 #endif   /* PROC_H */