1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

getpid/pid cleanup

This commit is contained in:
Bruce Momjian
1998-01-25 05:15:15 +00:00
parent fc75484550
commit c16ebb0f67
16 changed files with 61 additions and 102 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.31 1998/01/07 21:04:49 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.32 1998/01/25 05:13:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1828,14 +1828,10 @@ refcount = %ld, file: %s, line: %d\n",
_bm_trace(Oid dbId, Oid relId, int blkNo, int bufNo, int allocType)
{
static int mypid = 0;
long start,
cur;
bmtrace *tb;
if (mypid == 0)
mypid = getpid();
start = *CurTraceBuf;
if (start > 0)
@@ -1871,7 +1867,7 @@ _bm_trace(Oid dbId, Oid relId, int blkNo, int bufNo, int allocType)
okay:
tb = &TraceBuf[start];
tb->bmt_pid = mypid;
tb->bmt_pid = MyProcPid;
tb->bmt_buf = bufNo;
tb->bmt_dbid = dbId;
tb->bmt_relid = relId;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.20 1998/01/23 22:16:46 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.21 1998/01/25 05:14:02 momjian Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -37,6 +37,7 @@
#include <unistd.h>
#include "postgres.h"
#include "miscadmin.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "storage/proc.h"
@@ -77,7 +78,7 @@ static char *lock_types[] = {
if ((lockDebug >= 1) && (tag->relId >= lock_debug_oid_min)) \
elog(DEBUG, \
"%s: pid (%d) rel (%d) dbid (%d) tid (%d,%d) type (%s)",where, \
getpid(),\
MyProcPid,\
tag->relId, tag->dbId, \
((tag->tupleId.ip_blkid.bi_hi<<16)+\
tag->tupleId.ip_blkid.bi_lo),\
@@ -92,7 +93,7 @@ static char *lock_types[] = {
elog(DEBUG, \
"%s: pid (%d) rel (%d) dbid (%d) tid (%d,%d) nHolding (%d) "\
"holders (%d,%d,%d,%d,%d) type (%s)",where, \
getpid(),\
MyProcPid,\
lock->tag.relId, lock->tag.dbId, \
((lock->tag.tupleId.ip_blkid.bi_hi<<16)+\
lock->tag.tupleId.ip_blkid.bi_lo),\
@@ -113,7 +114,7 @@ static char *lock_types[] = {
"%s: pid (%d) xid (%d) pid (%d) lock (%x) nHolding (%d) "\
"holders (%d,%d,%d,%d,%d)",\
where,\
getpid(),\
MyProcPid,\
xidentP->tag.xid,\
xidentP->tag.pid,\
xidentP->tag.lock,\
@@ -550,7 +551,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt)
#ifdef USER_LOCKS
if (is_user_lock)
{
item.tag.pid = getpid();
item.tag.pid = MyProcPid;
item.tag.xid = myXid = 0;
#ifdef USER_LOCKS_DEBUG
elog(NOTICE, "LockAcquire: user lock xid [%d,%d,%d]",
@@ -975,7 +976,7 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt)
#ifdef USER_LOCKS
if (is_user_lock)
{
item.tag.pid = getpid();
item.tag.pid = MyProcPid;
item.tag.xid = 0;
#ifdef USER_LOCKS_DEBUG
elog(NOTICE, "LockRelease: user lock xid [%d,%d,%d]",
@@ -1153,14 +1154,12 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue)
#ifdef USER_LOCKS
int is_user_lock_table,
my_pid,
count,
nskip;
is_user_lock_table = (tableId == 0);
my_pid = getpid();
#ifdef USER_LOCKS_DEBUG
elog(NOTICE, "LockReleaseAll: tableId=%d, pid=%d", tableId, my_pid);
elog(NOTICE, "LockReleaseAll: tableId=%d, pid=%d", tableId, MyProcPid);
#endif
if (is_user_lock_table)
{
@@ -1226,7 +1225,7 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue)
nskip++;
goto next_item;
}
if (xidLook->tag.pid != my_pid)
if (xidLook->tag.pid != MyProcPid)
{
/* This should never happen */
#ifdef USER_LOCKS_DEBUG
@@ -1433,13 +1432,11 @@ DumpLocks()
SPINLOCK masterLock;
int nLockTypes;
LOCK *lock;
int pid,
count;
int tableId = 1;
LOCKTAB *ltable;
pid = getpid();
ShmemPIDLookup(pid, &location);
ShmemPIDLookup(MyProcPid, &location);
if (location == INVALID_OFFSET)
return;
proc = (PROC *) MAKE_PTR(location);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.27 1998/01/23 22:16:48 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.28 1998/01/25 05:14:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95
*
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.27 1998/01/23 22:16:48 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.28 1998/01/25 05:14:09 momjian Exp $
*/
#include <sys/time.h>
#include <unistd.h>
@@ -127,7 +127,6 @@ InitProcGlobal(IPCKey key)
{
int i;
ProcGlobal->numProcs = 0;
ProcGlobal->freeProcs = INVALID_OFFSET;
ProcGlobal->currKey = IPCGetProcessSemaphoreInitKey(key);
for (i = 0; i < MAX_PROC_SEMS / PROC_NSEMS_PER_SET; i++)
@@ -144,7 +143,6 @@ void
InitProcess(IPCKey key)
{
bool found = false;
int pid;
int semstat;
unsigned long location,
myOffset;
@@ -201,8 +199,6 @@ InitProcess(IPCKey key)
/* this cannot be initialized until after the buffer pool */
SHMQueueInit(&(MyProc->lockQueue));
MyProc->procId = ProcGlobal->numProcs;
ProcGlobal->numProcs++;
}
/*
@@ -253,11 +249,8 @@ InitProcess(IPCKey key)
*/
SpinRelease(ProcStructLock);
MyProc->pid = 0;
MyProc->pid = MyProcPid;
MyProc->xid = InvalidTransactionId;
#if 0
MyProc->pid = MyPid;
#endif
/* ----------------
* Start keeping spin lock stats from here on. Any botch before
@@ -273,9 +266,8 @@ InitProcess(IPCKey key)
* exit.
* -------------------------
*/
pid = getpid();
location = MAKE_OFFSET(MyProc);
if ((!ShmemPIDLookup(pid, &location)) || (location != MAKE_OFFSET(MyProc)))
if ((!ShmemPIDLookup(MyProcPid, &location)) || (location != MAKE_OFFSET(MyProc)))
{
elog(FATAL, "InitProc: ShmemPID table broken");
}
@@ -283,7 +275,7 @@ InitProcess(IPCKey key)
MyProc->errType = NO_ERROR;
SHMQueueElemInit(&(MyProc->links));
on_exitpg(ProcKill, (caddr_t) pid);
on_exitpg(ProcKill, (caddr_t) MyProcPid);
ProcInitialized = TRUE;
}
@@ -352,12 +344,7 @@ ProcKill(int exitStatus, int pid)
if (exitStatus != 0)
return;
if (!pid)
{
pid = getpid();
}
ShmemPIDLookup(pid, &location);
ShmemPIDLookup(MyProcPid, &location);
if (location == INVALID_OFFSET)
return;
@@ -365,7 +352,7 @@ ProcKill(int exitStatus, int pid)
if (proc != MyProc)
{
Assert(pid != getpid());
Assert(pid != MyProcPid);
}
else
MyProc = NULL;
@@ -478,7 +465,7 @@ ProcSleep(PROC_QUEUE *queue,
MyProc->prio = prio;
MyProc->token = token;
MyProc->waitLock = lock;
/* -------------------
* currently, we only need this for the ProcWakeup routines
* -------------------
@@ -572,19 +559,6 @@ ProcWakeup(PROC *proc, int errType)
return retProc;
}
/*
* ProcGetId --
*/
#ifdef NOT_USED
int
ProcGetId()
{
return (MyProc->procId);
}
#endif
/*
* ProcLockWakeup -- routine for waking up processes when a lock is
* released.
@@ -652,8 +626,7 @@ ProcAddLock(SHM_QUEUE *elem)
static void
HandleDeadLock(int sig)
{
LOCK *lock;
int size;
LOCK *mywaitlock;
LockLockTable();
@@ -692,8 +665,7 @@ HandleDeadLock(int sig)
return;
}
lock = MyProc->waitLock;
size = lock->waitProcs.size;/* so we can look at this in the core */
mywaitlock = MyProc->waitLock;
#ifdef DEADLOCK_DEBUG
DumpLocks();
@@ -703,8 +675,8 @@ HandleDeadLock(int sig)
* Get this process off the lock's wait queue
* ------------------------
*/
Assert(lock->waitProcs.size > 0);
--lock->waitProcs.size;
Assert(mywaitlock->waitProcs.size > 0);
--mywaitlock->waitProcs.size;
SHMQueueDelete(&(MyProc->links));
SHMQueueElemInit(&(MyProc->links));