1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* proc.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1998-07-27 21:38:40 +02:00
|
|
|
* $Id: proc.h,v 1.13 1998/07/27 19:38:38 vadim Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _PROC_H_
|
|
|
|
#define _PROC_H_
|
|
|
|
|
1996-11-05 07:11:08 +01:00
|
|
|
#include <storage/lock.h>
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int sleeplock;
|
|
|
|
int semNum;
|
|
|
|
IpcSemaphoreId semId;
|
1997-09-07 07:04:48 +02:00
|
|
|
IpcSemaphoreKey semKey;
|
1997-09-08 23:56:23 +02:00
|
|
|
} SEMA;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each backend has:
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct proc
|
|
|
|
{
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* proc->links MUST BE THE FIRST ELEMENT OF STRUCT (see ProcWakeup()) */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
SHM_QUEUE links; /* proc can be waiting for one event(lock) */
|
|
|
|
SEMA sem; /* ONE semaphore to sleep on */
|
|
|
|
int errType; /* error code tells why we woke up */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int critSects; /* If critSects > 0, we are in sensitive
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines that cannot be recovered when
|
|
|
|
* the process fails. */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int prio; /* priority for sleep queue */
|
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-07-27 21:38:40 +02:00
|
|
|
#ifdef LowLevelLocking
|
|
|
|
TransactionId xmin; /* minimal running XID as it was when
|
|
|
|
* we were starting our xact: vacuum
|
|
|
|
* must not remove tuples deleted by
|
|
|
|
* xid >= xmin !
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
LOCK *waitLock; /* Lock we're sleeping on */
|
|
|
|
int token; /* info for proc wakeup routines */
|
|
|
|
int pid; /* This procs process id */
|
|
|
|
short sLocks[MAX_SPINS]; /* Spin lock stats */
|
|
|
|
SHM_QUEUE lockQueue; /* locks associated with current
|
1997-09-07 07:04:48 +02:00
|
|
|
* transaction */
|
1997-09-08 23:56:23 +02:00
|
|
|
} PROC;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MAX_PROC_SEMS is the maximum number of per-process semaphores (those used
|
|
|
|
* by the lock mgr) we can keep track of. PROC_NSEMS_PER_SET is the number
|
|
|
|
* of semaphores in each (sys-V) semaphore set allocated. (Be careful not
|
|
|
|
* to set it to greater 32. Otherwise, the bitmap will overflow.)
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MAX_PROC_SEMS 128
|
|
|
|
#define PROC_NSEMS_PER_SET 16
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct procglobal
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
SHMEM_OFFSET freeProcs;
|
|
|
|
IPCKey currKey;
|
|
|
|
int32 freeSemMap[MAX_PROC_SEMS / PROC_NSEMS_PER_SET];
|
1997-09-08 23:56:23 +02:00
|
|
|
} PROC_HDR;
|
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
|
|
|
|
|
|
|
#define PROC_INCR_SLOCK(lock) if (MyProc) (MyProc->sLocks[(lock)])++
|
|
|
|
#define PROC_DECR_SLOCK(lock) if (MyProc) (MyProc->sLocks[(lock)])--
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flags explaining why process woke up
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define NO_ERROR 0
|
|
|
|
#define ERR_TIMEOUT 1
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ERR_BUFFER_IO 2
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MAX_PRIO 50
|
|
|
|
#define MIN_PRIO (-1)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
extern SPINLOCK ProcStructLock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function Prototypes
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void InitProcess(IPCKey key);
|
|
|
|
extern void ProcReleaseLocks(void);
|
|
|
|
extern bool ProcRemove(int pid);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* extern bool ProcKill(int exitStatus, int pid); */
|
|
|
|
/* make static in storage/lmgr/proc.c -- jolly */
|
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void ProcQueueInit(PROC_QUEUE *queue);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern int
|
|
|
|
ProcSleep(PROC_QUEUE *queue, SPINLOCK spinlock, int token,
|
1997-09-08 23:56:23 +02:00
|
|
|
int prio, LOCK *lock);
|
1998-06-30 04:33:34 +02:00
|
|
|
extern int ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod, LOCK *lock);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void ProcAddLock(SHM_QUEUE *elem);
|
|
|
|
extern void ProcReleaseSpins(PROC *proc);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void ProcFreeAllSemaphores(void);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* PROC_H */
|