1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* proc.h
|
2000-11-29 00:27:57 +01:00
|
|
|
* per-process shared memory data structures
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2001-09-29 23:35:14 +02:00
|
|
|
* $Id: proc.h,v 1.49 2001/09/29 21:35:14 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _PROC_H_
|
|
|
|
#define _PROC_H_
|
|
|
|
|
1999-09-27 17:48:12 +02:00
|
|
|
#include "access/xlog.h"
|
2001-07-06 23:04:26 +02:00
|
|
|
#include "storage/backendid.h"
|
2001-09-29 06:02:27 +02:00
|
|
|
#include "storage/ipc.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/lock.h"
|
1996-11-05 07:11:08 +01:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-01-14 06:08:17 +01:00
|
|
|
IpcSemaphoreId semId; /* SysV semaphore set ID */
|
|
|
|
int semNum; /* semaphore number within set */
|
1997-09-08 23:56:23 +02:00
|
|
|
} SEMA;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
2001-01-22 23:30:06 +01:00
|
|
|
* Each backend has a PROC struct in shared memory. There is also a list of
|
|
|
|
* currently-unused PROC structs that will be reallocated to new backends.
|
2001-01-16 07:11:34 +01:00
|
|
|
*
|
|
|
|
* links: list link for any list the PROC is in. When waiting for a lock,
|
|
|
|
* the PROC is linked into that lock's waitProcs queue. A recycled PROC
|
|
|
|
* is linked into ProcGlobal's freeProcs list.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2001-09-29 06:02:27 +02:00
|
|
|
struct PROC
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-01-22 23:30:06 +01:00
|
|
|
/* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
|
2001-01-16 07:11:34 +01:00
|
|
|
SHM_QUEUE links; /* list link if process is in a list */
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
SEMA sem; /* ONE semaphore to sleep on */
|
2001-01-25 04:31:16 +01:00
|
|
|
int errType; /* STATUS_OK or STATUS_ERROR after wakeup */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
TransactionId xid; /* transaction currently being executed by
|
1997-09-07 07:04:48 +02:00
|
|
|
* this proc */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
TransactionId xmin; /* minimal running XID as it was when we
|
|
|
|
* were starting our xact: vacuum must not
|
|
|
|
* remove tuples deleted by xid >= xmin ! */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
int pid; /* This backend's process id */
|
|
|
|
Oid databaseId; /* OID of database this backend is using */
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
/*
|
|
|
|
* XLOG location of first XLOG record written by this backend's
|
|
|
|
* current transaction. If backend is not in a transaction or hasn't
|
|
|
|
* yet modified anything, logRec.xrecoff is zero.
|
2001-02-26 01:50:08 +01:00
|
|
|
*/
|
1999-09-27 17:48:12 +02:00
|
|
|
XLogRecPtr logRec;
|
2000-12-22 01:51:54 +01:00
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
/* Info about LWLock the process is currently waiting for, if any. */
|
|
|
|
bool lwWaiting; /* true if waiting for an LW lock */
|
|
|
|
bool lwExclusive; /* true if waiting for exclusive access */
|
|
|
|
struct PROC *lwWaitLink; /* next waiter for same LW lock */
|
|
|
|
|
2001-01-22 23:30:06 +01:00
|
|
|
/* Info about lock the process is currently waiting for, if any. */
|
|
|
|
/* waitLock and waitHolder are NULL if not currently waiting. */
|
2000-12-22 01:51:54 +01:00
|
|
|
LOCK *waitLock; /* Lock object we're sleeping on ... */
|
2001-09-29 23:35:14 +02:00
|
|
|
PROCLOCK *waitHolder; /* Per-holder info for awaited lock */
|
2000-12-22 01:51:54 +01:00
|
|
|
LOCKMODE waitLockMode; /* type of lock we're waiting for */
|
2001-01-16 07:11:34 +01:00
|
|
|
LOCKMASK heldLocks; /* bitmask for lock types already held on
|
|
|
|
* this lock object by this backend */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
2001-09-29 23:35:14 +02:00
|
|
|
SHM_QUEUE procHolders; /* list of PROCLOCK objects for locks held
|
2001-03-22 05:01:46 +01:00
|
|
|
* or awaited by this backend */
|
2000-12-22 01:51:54 +01:00
|
|
|
};
|
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
/* NOTE: "typedef struct PROC PROC" appears in storage/lock.h. */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern PROC *MyProc;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-29 00:27:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There is one ProcGlobal struct for the whole installation.
|
|
|
|
*
|
|
|
|
* PROC_NSEMS_PER_SET is the number of semaphores in each sys-V semaphore set
|
|
|
|
* we allocate. It must be no more than 32 (or however many bits in an int
|
|
|
|
* on your machine), or our free-semaphores bitmap won't work. It also must
|
|
|
|
* be *less than* your kernel's SEMMSL (max semaphores per set) parameter,
|
|
|
|
* which is often around 25. (Less than, because we allocate one extra sema
|
|
|
|
* in each set for identification purposes.)
|
|
|
|
*
|
|
|
|
* PROC_SEM_MAP_ENTRIES is the number of semaphore sets we need to allocate
|
2001-09-07 02:27:30 +02:00
|
|
|
* to keep track of up to maxBackends backends.
|
2000-11-29 00:27:57 +01:00
|
|
|
*/
|
|
|
|
#define PROC_NSEMS_PER_SET 16
|
2001-09-07 02:27:30 +02:00
|
|
|
#define PROC_SEM_MAP_ENTRIES(maxBackends) (((maxBackends)-1)/PROC_NSEMS_PER_SET+1)
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* info about a single set of per-process semaphores */
|
|
|
|
IpcSemaphoreId procSemId;
|
|
|
|
int32 freeSemMap;
|
|
|
|
/*
|
|
|
|
* In freeSemMap, bit i is set if the i'th semaphore of this sema
|
|
|
|
* set is allocated to a process. (i counts from 0 at the LSB)
|
|
|
|
*/
|
|
|
|
} SEM_MAP_ENTRY;
|
2000-11-29 00:27:57 +01:00
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
typedef struct PROC_HDR
|
2000-11-29 00:27:57 +01:00
|
|
|
{
|
|
|
|
/* Head of list of free PROC structures */
|
|
|
|
SHMEM_OFFSET freeProcs;
|
|
|
|
|
|
|
|
/* Info about semaphore sets used for per-process semaphores */
|
2001-09-07 02:27:30 +02:00
|
|
|
int semMapEntries;
|
2000-11-29 00:27:57 +01:00
|
|
|
/*
|
2001-09-07 02:27:30 +02:00
|
|
|
* VARIABLE LENGTH ARRAY: actual length is semMapEntries.
|
|
|
|
* THIS MUST BE LAST IN THE STRUCT DECLARATION.
|
2000-11-29 00:27:57 +01:00
|
|
|
*/
|
2001-09-07 02:27:30 +02:00
|
|
|
SEM_MAP_ENTRY procSemMap[1];
|
2000-11-29 00:27:57 +01:00
|
|
|
} PROC_HDR;
|
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
|
|
|
|
/* configurable option */
|
|
|
|
extern int DeadlockTimeout;
|
|
|
|
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* Function Prototypes
|
|
|
|
*/
|
2000-11-29 00:27:57 +01:00
|
|
|
extern void InitProcGlobal(int maxBackends);
|
|
|
|
extern void InitProcess(void);
|
2001-09-29 06:02:27 +02:00
|
|
|
extern void InitDummyProcess(void);
|
2000-12-22 01:51:54 +01:00
|
|
|
extern void ProcReleaseLocks(bool isCommit);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void ProcQueueInit(PROC_QUEUE *queue);
|
2001-01-25 04:31:16 +01:00
|
|
|
extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
|
2001-09-29 23:35:14 +02:00
|
|
|
LOCK *lock, PROCLOCK *holder);
|
1999-05-13 17:55:45 +02:00
|
|
|
extern PROC *ProcWakeup(PROC *proc, int errType);
|
2001-01-25 04:31:16 +01:00
|
|
|
extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
|
2001-01-16 21:59:34 +01:00
|
|
|
extern bool LockWaitCancel(void);
|
2001-01-14 06:08:17 +01:00
|
|
|
extern void HandleDeadLock(SIGNAL_ARGS);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-07-06 23:04:26 +02:00
|
|
|
extern void ProcWaitForSignal(void);
|
|
|
|
extern void ProcCancelWaitForSignal(void);
|
|
|
|
extern void ProcSendSignal(BackendId procId);
|
|
|
|
|
2001-09-21 19:06:12 +02:00
|
|
|
extern bool enable_sigalrm_interrupt(int delayms);
|
|
|
|
extern bool disable_sigalrm_interrupt(void);
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* PROC_H */
|