]> granicus.if.org Git - postgresql/blob - src/include/storage/proc.h
Oops, only wanted python change in the last commit. Backing out.
[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-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: proc.h,v 1.43 2001/05/25 15:45:34 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
20 /* configurable option */
21 extern int      DeadlockTimeout;
22
23 typedef struct
24 {
25         IpcSemaphoreId semId;           /* SysV semaphore set ID */
26         int                     semNum;                 /* semaphore number within set */
27 } SEMA;
28
29 /*
30  * Each backend has a PROC struct in shared memory.  There is also a list of
31  * currently-unused PROC structs that will be reallocated to new backends.
32  *
33  * links: list link for any list the PROC is in.  When waiting for a lock,
34  * the PROC is linked into that lock's waitProcs queue.  A recycled PROC
35  * is linked into ProcGlobal's freeProcs list.
36  */
37 struct proc
38 {
39         /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
40
41         SHM_QUEUE       links;                  /* list link if process is in a list */
42
43         SEMA            sem;                    /* ONE semaphore to sleep on */
44         int                     errType;                /* STATUS_OK or STATUS_ERROR after wakeup */
45
46         TransactionId xid;                      /* transaction currently being executed by
47                                                                  * this proc */
48
49         TransactionId xmin;                     /* minimal running XID as it was when we
50                                                                  * were starting our xact: vacuum must not
51                                                                  * remove tuples deleted by xid >= xmin ! */
52
53         /*
54          * XLOG location of first XLOG record written by this backend's
55          * current transaction.  If backend is not in a transaction or hasn't
56          * yet modified anything, logRec.xrecoff is zero.
57          */
58         XLogRecPtr      logRec;
59
60         /* Info about lock the process is currently waiting for, if any. */
61         /* waitLock and waitHolder are NULL if not currently waiting. */
62         LOCK       *waitLock;           /* Lock object we're sleeping on ... */
63         HOLDER     *waitHolder;         /* Per-holder info for awaited lock */
64         LOCKMODE        waitLockMode;   /* type of lock we're waiting for */
65         LOCKMASK        heldLocks;              /* bitmask for lock types already held on
66                                                                  * this lock object by this backend */
67
68         int                     pid;                    /* This backend's process id */
69         Oid                     databaseId;             /* OID of database this backend is using */
70
71         short           sLocks[MAX_SPINS];              /* Spin lock stats */
72         SHM_QUEUE       procHolders;    /* list of HOLDER objects for locks held
73                                                                  * or awaited by this backend */
74 };
75
76 /* NOTE: "typedef struct proc PROC" appears in storage/lock.h. */
77
78
79 extern PROC *MyProc;
80
81 extern SPINLOCK ProcStructLock;
82
83
84 #define PROC_INCR_SLOCK(lock) \
85 do { \
86         if (MyProc) (MyProc->sLocks[(lock)])++; \
87 } while (0)
88
89 #define PROC_DECR_SLOCK(lock) \
90 do { \
91         if (MyProc) (MyProc->sLocks[(lock)])--; \
92 } while (0)
93
94
95 /*
96  * There is one ProcGlobal struct for the whole installation.
97  *
98  * PROC_NSEMS_PER_SET is the number of semaphores in each sys-V semaphore set
99  * we allocate.  It must be no more than 32 (or however many bits in an int
100  * on your machine), or our free-semaphores bitmap won't work.  It also must
101  * be *less than* your kernel's SEMMSL (max semaphores per set) parameter,
102  * which is often around 25.  (Less than, because we allocate one extra sema
103  * in each set for identification purposes.)
104  *
105  * PROC_SEM_MAP_ENTRIES is the number of semaphore sets we need to allocate
106  * to keep track of up to MAXBACKENDS backends.
107  */
108 #define  PROC_NSEMS_PER_SET             16
109 #define  PROC_SEM_MAP_ENTRIES   ((MAXBACKENDS-1)/PROC_NSEMS_PER_SET+1)
110
111 typedef struct procglobal
112 {
113         /* Head of list of free PROC structures */
114         SHMEM_OFFSET freeProcs;
115
116         /* Info about semaphore sets used for per-process semaphores */
117         IpcSemaphoreId procSemIds[PROC_SEM_MAP_ENTRIES];
118         int32           freeSemMap[PROC_SEM_MAP_ENTRIES];
119
120         /*
121          * In each freeSemMap entry, bit i is set if the i'th semaphore of the
122          * set is allocated to a process.  (i counts from 0 at the LSB)
123          */
124 } PROC_HDR;
125
126 /*
127  * Function Prototypes
128  */
129 extern void InitProcGlobal(int maxBackends);
130 extern void InitProcess(void);
131 extern void ProcReleaseLocks(bool isCommit);
132 extern bool ProcRemove(int pid);
133
134 extern void ProcQueueInit(PROC_QUEUE *queue);
135 extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
136                   LOCK *lock, HOLDER *holder);
137 extern PROC *ProcWakeup(PROC *proc, int errType);
138 extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
139 extern void ProcReleaseSpins(PROC *proc);
140 extern bool LockWaitCancel(void);
141 extern void HandleDeadLock(SIGNAL_ARGS);
142
143 #endif   /* PROC_H */