aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2003-12-20 17:31:21 +0000
committerBruce Momjian <bruce@momjian.us>2003-12-20 17:31:21 +0000
commitd75b2ec4ebbc7fdb51088e89da47c6523bf2c640 (patch)
tree4f0a12508b01da4d98c663bbdadb4a2e1ae6837a /src/backend/storage
parent1ee0ddf91df31669ca0d07871d3f5aa88791b78d (diff)
downloadpostgresql-d75b2ec4ebbc7fdb51088e89da47c6523bf2c640.tar.gz
postgresql-d75b2ec4ebbc7fdb51088e89da47c6523bf2c640.zip
This patch is the next step towards (re)allowing fork/exec.
Claudio Natoli
Diffstat (limited to 'src/backend/storage')
-rw-r--r--src/backend/storage/buffer/buf_init.c6
-rw-r--r--src/backend/storage/file/fd.c15
-rw-r--r--src/backend/storage/freespace/freespace.c22
-rw-r--r--src/backend/storage/ipc/ipci.c28
-rw-r--r--src/backend/storage/ipc/pmsignal.c6
-rw-r--r--src/backend/storage/ipc/shmem.c137
-rw-r--r--src/backend/storage/ipc/sinvaladt.c7
-rw-r--r--src/backend/storage/lmgr/lock.c48
-rw-r--r--src/backend/storage/lmgr/lwlock.c4
-rw-r--r--src/backend/storage/lmgr/proc.c5
10 files changed, 174 insertions, 104 deletions
diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c
index 1c66b950a51..1a707568b55 100644
--- a/src/backend/storage/buffer/buf_init.c
+++ b/src/backend/storage/buffer/buf_init.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.59 2003/12/14 00:34:47 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.60 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -125,7 +125,9 @@ InitBufferPool(void)
* anyone else attached to the shmem at this point, we've got
* problems.
*/
+#ifndef EXEC_BACKEND
LWLockAcquire(BufMgrLock, LW_EXCLUSIVE);
+#endif
BufferDescriptors = (BufferDesc *)
ShmemInitStruct("Buffer Descriptors",
@@ -177,7 +179,9 @@ InitBufferPool(void)
/* Init other shared buffer-management stuff */
StrategyInitialize(!foundDescs);
+#ifndef EXEC_BACKEND
LWLockRelease(BufMgrLock);
+#endif
}
/*
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 78814d77b63..4875b7f2bcf 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.104 2003/12/12 18:45:09 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.105 2003/12/20 17:31:21 momjian Exp $
*
* NOTES:
*
@@ -53,11 +53,6 @@
#include "storage/ipc.h"
-/* Filename components for OpenTemporaryFile */
-#define PG_TEMP_FILES_DIR "pgsql_tmp"
-#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
-
-
/*
* Problem: Postgres does a system(ld...) to do dynamic loading.
* This will open several extra files in addition to those used by
@@ -1217,8 +1212,12 @@ RemovePgTempFiles(void)
{
while ((db_de = readdir(db_dir)) != NULL)
{
- if (strcmp(db_de->d_name, ".") == 0 ||
- strcmp(db_de->d_name, "..") == 0)
+ if (strcmp(db_de->d_name, ".") == 0
+#ifndef EXEC_BACKEND
+ /* no PG_TEMP_FILES_DIR in DataDir in non EXEC_BACKEND case */
+ || strcmp(db_de->d_name, "..") == 0
+#endif
+ )
continue;
snprintf(temp_path, sizeof(temp_path),
diff --git a/src/backend/storage/freespace/freespace.c b/src/backend/storage/freespace/freespace.c
index a7bffb5c733..84f5c65c928 100644
--- a/src/backend/storage/freespace/freespace.c
+++ b/src/backend/storage/freespace/freespace.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.27 2003/12/12 18:45:09 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.28 2003/12/20 17:31:21 momjian Exp $
*
*
* NOTES:
@@ -180,7 +180,6 @@ typedef struct FSMRelation FSMRelation;
/* Header for whole map */
struct FSMHeader
{
- HTAB *relHash; /* hashtable of FSMRelation entries */
FSMRelation *usageList; /* FSMRelations in usage-recency order */
FSMRelation *usageListTail; /* tail of usage-recency list */
FSMRelation *firstRel; /* FSMRelations in arena storage order */
@@ -218,6 +217,7 @@ int MaxFSMRelations; /* these are set by guc.c */
int MaxFSMPages;
static FSMHeader *FreeSpaceMap; /* points to FSMHeader in shared memory */
+static HTAB *FreeSpaceMapRelHash; /* points to (what used to be) FSMHeader->relHash */
static FSMRelation *lookup_fsm_rel(RelFileNode *rel);
@@ -265,13 +265,15 @@ InitFreeSpaceMap(void)
{
HASHCTL info;
int nchunks;
+ bool found;
/* Create table header */
- FreeSpaceMap = (FSMHeader *) ShmemAlloc(sizeof(FSMHeader));
+ FreeSpaceMap = (FSMHeader *) ShmemInitStruct("Free Space Map Header",sizeof(FSMHeader),&found);
if (FreeSpaceMap == NULL)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("insufficient shared memory for free space map")));
+ if (!found)
MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
/* Create hashtable for FSMRelations */
@@ -279,17 +281,21 @@ InitFreeSpaceMap(void)
info.entrysize = sizeof(FSMRelation);
info.hash = tag_hash;
- FreeSpaceMap->relHash = ShmemInitHash("Free Space Map Hash",
+ FreeSpaceMapRelHash = ShmemInitHash("Free Space Map Hash",
MaxFSMRelations / 10,
MaxFSMRelations,
&info,
(HASH_ELEM | HASH_FUNCTION));
- if (!FreeSpaceMap->relHash)
+ if (!FreeSpaceMapRelHash)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("insufficient shared memory for free space map")));
+ if (found)
+ return;
+
+
/* Allocate page-storage arena */
nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;
/* This check ensures spareChunks will be greater than zero */
@@ -974,7 +980,7 @@ lookup_fsm_rel(RelFileNode *rel)
{
FSMRelation *fsmrel;
- fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
+ fsmrel = (FSMRelation *) hash_search(FreeSpaceMapRelHash,
(void *) rel,
HASH_FIND,
NULL);
@@ -995,7 +1001,7 @@ create_fsm_rel(RelFileNode *rel)
FSMRelation *fsmrel;
bool found;
- fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
+ fsmrel = (FSMRelation *) hash_search(FreeSpaceMapRelHash,
(void *) rel,
HASH_ENTER,
&found);
@@ -1050,7 +1056,7 @@ delete_fsm_rel(FSMRelation *fsmrel)
unlink_fsm_rel_usage(fsmrel);
unlink_fsm_rel_storage(fsmrel);
FreeSpaceMap->numRels--;
- result = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
+ result = (FSMRelation *) hash_search(FreeSpaceMapRelHash,
(void *) &(fsmrel->key),
HASH_REMOVE,
NULL);
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 982846843a5..eaf22a095f1 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.59 2003/12/01 21:59:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.60 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -87,7 +87,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
/*
* Set up shared memory allocation mechanism
*/
- InitShmemAllocation(seghdr);
+ InitShmemAllocation(seghdr, true);
/*
* Now initialize LWLocks, which do shared memory allocation and are
@@ -135,12 +135,36 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
}
+#ifdef EXEC_BACKEND
/*
* AttachSharedMemoryAndSemaphores
* Attaches to the existing shared resources.
*/
+
+/* FIXME: [fork/exec] This function is starting to look pretty much like
+ CreateSharedMemoryAndSemaphores. Refactor? */
void
AttachSharedMemoryAndSemaphores(void)
{
+ PGShmemHeader *seghdr = PGSharedMemoryCreate(-1,false,-1);
+
+ InitShmemAllocation(seghdr, false);
+
+ InitShmemIndex();
+
+ XLOGShmemInit();
CLOGShmemInit();
+ InitBufferPool();
+
+ InitLocks();
+ InitLockTable(MaxBackends);
+
+ InitProcGlobal(MaxBackends);
+
+ CreateSharedInvalidationState(MaxBackends);
+
+ InitFreeSpaceMap();
+
+ PMSignalInit();
}
+#endif
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c
index 6545c748d37..fb2b2faca0f 100644
--- a/src/backend/storage/ipc/pmsignal.c
+++ b/src/backend/storage/ipc/pmsignal.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.6 2003/11/29 19:51:56 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.7 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,9 +44,11 @@ static volatile sig_atomic_t *PMSignalFlags;
void
PMSignalInit(void)
{
+ bool found;
PMSignalFlags = (sig_atomic_t *)
- ShmemAlloc(NUM_PMSIGNALS * sizeof(sig_atomic_t));
+ ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found);
+ if (!found)
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
}
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index b4e1439d154..598597f0aa0 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.74 2003/11/29 19:51:56 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.75 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -74,7 +74,11 @@ SHMEM_OFFSET ShmemBase; /* start address of shared memory */
static SHMEM_OFFSET ShmemEnd; /* end+1 address of shared memory */
-static slock_t *ShmemLock; /* spinlock for shared memory allocation */
+NON_EXEC_STATIC slock_t *ShmemLock; /* spinlock for shared memory allocation */
+
+NON_EXEC_STATIC slock_t *ShmemIndexLock; /* spinlock for ShmemIndex */
+
+NON_EXEC_STATIC void *ShmemIndexAlloc = NULL; /* Memory actually allocated for ShmemIndex */
static HTAB *ShmemIndex = NULL; /* primary index hashtable for shmem */
@@ -88,7 +92,7 @@ static bool ShmemBootstrap = false; /* bootstrapping shmem index? */
* but we use void to avoid having to include ipc.h in shmem.h.
*/
void
-InitShmemAllocation(void *seghdr)
+InitShmemAllocation(void *seghdr, bool init)
{
PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr;
@@ -97,26 +101,34 @@ InitShmemAllocation(void *seghdr)
ShmemBase = (SHMEM_OFFSET) shmhdr;
ShmemEnd = ShmemBase + shmhdr->totalsize;
- /*
- * Initialize the spinlock used by ShmemAlloc. We have to do the
- * space allocation the hard way, since ShmemAlloc can't be called
- * yet.
- */
- ShmemLock = (slock_t *) (((char *) shmhdr) + shmhdr->freeoffset);
- shmhdr->freeoffset += MAXALIGN(sizeof(slock_t));
- Assert(shmhdr->freeoffset <= shmhdr->totalsize);
-
- SpinLockInit(ShmemLock);
-
- /* ShmemIndex can't be set up yet (need LWLocks first) */
- ShmemIndex = (HTAB *) NULL;
-
- /*
- * Initialize ShmemVariableCache for transaction manager.
- */
- ShmemVariableCache = (VariableCache)
+ if (init)
+ {
+ /*
+ * Initialize the spinlocks used by ShmemAlloc/ShmemInitStruct. We
+ * have to do the space allocation the hard way, since ShmemAlloc
+ * can't be called yet.
+ */
+ ShmemLock = (slock_t *) (((char *) shmhdr) + shmhdr->freeoffset);
+ shmhdr->freeoffset += MAXALIGN(sizeof(slock_t));
+ Assert(shmhdr->freeoffset <= shmhdr->totalsize);
+
+ ShmemIndexLock = (slock_t *) (((char *) shmhdr) + shmhdr->freeoffset);
+ shmhdr->freeoffset += MAXALIGN(sizeof(slock_t));
+ Assert(shmhdr->freeoffset <= shmhdr->totalsize);
+
+ SpinLockInit(ShmemLock);
+ SpinLockInit(ShmemIndexLock);
+
+ /* ShmemIndex can't be set up yet (need LWLocks first) */
+ ShmemIndex = (HTAB *) NULL;
+
+ /*
+ * Initialize ShmemVariableCache for transaction manager.
+ */
+ ShmemVariableCache = (VariableCache)
ShmemAlloc(sizeof(*ShmemVariableCache));
- memset(ShmemVariableCache, 0, sizeof(*ShmemVariableCache));
+ memset(ShmemVariableCache, 0, sizeof(*ShmemVariableCache));
+ }
}
/*
@@ -218,25 +230,28 @@ InitShmemIndex(void)
/*
* Now, create an entry in the hashtable for the index itself.
*/
- MemSet(item.key, 0, SHMEM_INDEX_KEYSIZE);
- strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE);
-
- result = (ShmemIndexEnt *)
- hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
- if (!result)
- ereport(FATAL,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of shared memory")));
-
- Assert(ShmemBootstrap && !found);
-
- result->location = MAKE_OFFSET(ShmemIndex->hctl);
- result->size = SHMEM_INDEX_SIZE;
-
- ShmemBootstrap = false;
+ if (!IsUnderPostmaster)
+ {
+ MemSet(item.key, 0, SHMEM_INDEX_KEYSIZE);
+ strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE);
+
+ result = (ShmemIndexEnt *)
+ hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
+ if (!result)
+ ereport(FATAL,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of shared memory")));
+
+ Assert(ShmemBootstrap && !found);
+
+ result->location = MAKE_OFFSET(ShmemIndex->hctl);
+ result->size = SHMEM_INDEX_SIZE;
+
+ ShmemBootstrap = false;
+ }
/* now release the lock acquired in ShmemInitStruct */
- LWLockRelease(ShmemIndexLock);
+ SpinLockRelease(ShmemIndexLock);
}
/*
@@ -320,21 +335,33 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
strncpy(item.key, name, SHMEM_INDEX_KEYSIZE);
item.location = BAD_LOCATION;
- LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
+ SpinLockAcquire(ShmemIndexLock);
if (!ShmemIndex)
{
- /*
- * If the shmem index doesn't exist, we are bootstrapping: we must
- * be trying to init the shmem index itself.
- *
- * Notice that the ShmemIndexLock is held until the shmem index has
- * been completely initialized.
- */
- Assert(strcmp(name, "ShmemIndex") == 0);
- Assert(ShmemBootstrap);
- *foundPtr = FALSE;
- return ShmemAlloc(size);
+ if (IsUnderPostmaster)
+ {
+ /* Must be initializing a (non-standalone) backend */
+ Assert(strcmp(name, "ShmemIndex") == 0);
+ Assert(ShmemBootstrap);
+ Assert(ShmemIndexAlloc);
+ *foundPtr = TRUE;
+ }
+ else
+ {
+ /*
+ * If the shmem index doesn't exist, we are bootstrapping: we must
+ * be trying to init the shmem index itself.
+ *
+ * Notice that the ShmemIndexLock is held until the shmem index has
+ * been completely initialized.
+ */
+ Assert(strcmp(name, "ShmemIndex") == 0);
+ Assert(ShmemBootstrap);
+ *foundPtr = FALSE;
+ ShmemIndexAlloc = ShmemAlloc(size);
+ }
+ return ShmemIndexAlloc;
}
/* look it up in the shmem index */
@@ -343,7 +370,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
if (!result)
{
- LWLockRelease(ShmemIndexLock);
+ SpinLockRelease(ShmemIndexLock);
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
@@ -359,7 +386,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
*/
if (result->size != size)
{
- LWLockRelease(ShmemIndexLock);
+ SpinLockRelease(ShmemIndexLock);
elog(WARNING, "ShmemIndex entry size is wrong");
/* let caller print its message too */
@@ -376,7 +403,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
/* out of memory */
Assert(ShmemIndex);
hash_search(ShmemIndex, (void *) &item, HASH_REMOVE, NULL);
- LWLockRelease(ShmemIndexLock);
+ SpinLockRelease(ShmemIndexLock);
ereport(WARNING,
(errcode(ERRCODE_OUT_OF_MEMORY),
@@ -389,6 +416,6 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
}
Assert(ShmemIsValid((unsigned long) structPtr));
- LWLockRelease(ShmemIndexLock);
+ SpinLockRelease(ShmemIndexLock);
return structPtr;
}
diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c
index ff26f9b86e4..a50cc4601e5 100644
--- a/src/backend/storage/ipc/sinvaladt.c
+++ b/src/backend/storage/ipc/sinvaladt.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.53 2003/11/29 19:51:56 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.54 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,10 +50,13 @@ SIBufferInit(int maxBackends)
int segSize;
SISeg *segP;
int i;
+ bool found;
/* Allocate space in shared memory */
segSize = SInvalShmemSize(maxBackends);
- shmInvalBuffer = segP = (SISeg *) ShmemAlloc(segSize);
+ shmInvalBuffer = segP = (SISeg *) ShmemInitStruct("shmInvalBuffer",segSize,&found);
+ if (found)
+ return;
/* Clear message counters, save size of procState array */
segP->minMsgNum = 0;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 6b450a1d358..8cb25b4ccdd 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.130 2003/12/01 21:59:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.131 2003/12/20 17:31:21 momjian Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -153,9 +153,11 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP)
* map from lock method id to the lock table structure
*/
static LockMethod LockMethods[MAX_LOCK_METHODS];
-
+static HTAB* LockMethodLockHash[MAX_LOCK_METHODS];
+static HTAB* LockMethodProcLockHash[MAX_LOCK_METHODS];
static int NumLockMethods;
+
/*
* InitLocks -- Init the lock module. Create a private data
* structure for constructing conflict masks.
@@ -245,8 +247,9 @@ LockMethodTableInit(char *tabName,
/*
* Lock the LWLock for the table (probably not necessary here)
*/
+#ifndef EXEC_BACKEND
LWLockAcquire(LockMgrLock, LW_EXCLUSIVE);
-
+#endif
/*
* no zero-th table
*/
@@ -279,15 +282,15 @@ LockMethodTableInit(char *tabName,
hash_flags = (HASH_ELEM | HASH_FUNCTION);
sprintf(shmemName, "%s (lock hash)", tabName);
- newLockMethod->lockHash = ShmemInitHash(shmemName,
+ LockMethodLockHash[NumLockMethods-1] = ShmemInitHash(shmemName,
init_table_size,
max_table_size,
&info,
hash_flags);
- if (!newLockMethod->lockHash)
+ if (!LockMethodLockHash[NumLockMethods-1])
elog(FATAL, "could not initialize lock table \"%s\"", tabName);
- Assert(newLockMethod->lockHash->hash == tag_hash);
+ Assert(LockMethodLockHash[NumLockMethods-1]->hash == tag_hash);
/*
* allocate a hash table for PROCLOCK structs. This is used to store
@@ -299,20 +302,21 @@ LockMethodTableInit(char *tabName,
hash_flags = (HASH_ELEM | HASH_FUNCTION);
sprintf(shmemName, "%s (proclock hash)", tabName);
- newLockMethod->proclockHash = ShmemInitHash(shmemName,
+ LockMethodProcLockHash[NumLockMethods-1] = ShmemInitHash(shmemName,
init_table_size,
max_table_size,
&info,
hash_flags);
- if (!newLockMethod->proclockHash)
+ if (!LockMethodProcLockHash[NumLockMethods-1])
elog(FATAL, "could not initialize lock table \"%s\"", tabName);
/* init data structures */
LockMethodInit(newLockMethod, conflictsP, numModes);
+#ifndef EXEC_BACKEND
LWLockRelease(LockMgrLock);
-
+#endif
pfree(shmemName);
return newLockMethod->lockmethodid;
@@ -449,8 +453,8 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
/*
* Find or create a lock with this tag
*/
- Assert(lockMethodTable->lockHash->hash == tag_hash);
- lock = (LOCK *) hash_search(lockMethodTable->lockHash,
+ Assert(LockMethodLockHash[lockmethodid]->hash == tag_hash);
+ lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) locktag,
HASH_ENTER, &found);
if (!lock)
@@ -497,7 +501,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
/*
* Find or create a proclock entry with this tag
*/
- proclockTable = lockMethodTable->proclockHash;
+ proclockTable = LockMethodProcLockHash[lockmethodid];
proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) &proclocktag,
HASH_ENTER, &found);
@@ -988,8 +992,8 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
/*
* Find a lock with this tag
*/
- Assert(lockMethodTable->lockHash->hash == tag_hash);
- lock = (LOCK *) hash_search(lockMethodTable->lockHash,
+ Assert(LockMethodLockHash[lockmethodid]->hash == tag_hash);
+ lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) locktag,
HASH_FIND, NULL);
@@ -1014,7 +1018,7 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
proclocktag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &proclocktag.xid);
- proclockTable = lockMethodTable->proclockHash;
+ proclockTable = LockMethodProcLockHash[lockmethodid];
proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) &proclocktag,
HASH_FIND_SAVE, NULL);
@@ -1086,8 +1090,8 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
* if there's no one waiting in the queue, we just released the
* last lock on this object. Delete it from the lock table.
*/
- Assert(lockMethodTable->lockHash->hash == tag_hash);
- lock = (LOCK *) hash_search(lockMethodTable->lockHash,
+ Assert(LockMethodLockHash[lockmethodid]->hash == tag_hash);
+ lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) &(lock->tag),
HASH_REMOVE,
NULL);
@@ -1269,7 +1273,7 @@ LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc,
/*
* remove the proclock entry from the hashtable
*/
- proclock = (PROCLOCK *) hash_search(lockMethodTable->proclockHash,
+ proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid],
(void *) proclock,
HASH_REMOVE,
NULL);
@@ -1287,8 +1291,8 @@ LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc,
* lock object.
*/
LOCK_PRINT("LockReleaseAll: deleting", lock, 0);
- Assert(lockMethodTable->lockHash->hash == tag_hash);
- lock = (LOCK *) hash_search(lockMethodTable->lockHash,
+ Assert(LockMethodLockHash[lockmethodid]->hash == tag_hash);
+ lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) &(lock->tag),
HASH_REMOVE, NULL);
if (!lock)
@@ -1367,7 +1371,7 @@ GetLockStatusData(void)
LWLockAcquire(LockMgrLock, LW_EXCLUSIVE);
- proclockTable = LockMethods[DEFAULT_LOCKMETHOD]->proclockHash;
+ proclockTable = LockMethodProcLockHash[DEFAULT_LOCKMETHOD];
data->nelements = i = proclockTable->hctl->nentries;
@@ -1480,7 +1484,7 @@ DumpAllLocks(void)
if (!lockMethodTable)
return;
- proclockTable = lockMethodTable->proclockHash;
+ proclockTable = LockMethodProcLockHash[lockmethodid];
if (proc->waitLock)
LOCK_PRINT("DumpAllLocks: waiting on", proc->waitLock, 0);
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 4142bb5198e..efb3ac4a90f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.18 2003/11/29 19:51:57 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.19 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -43,7 +43,7 @@ typedef struct LWLock
* the pointer by fork from the postmaster. LWLockIds are indexes into
* the array.
*/
-static LWLock *LWLockArray = NULL;
+NON_EXEC_STATIC LWLock *LWLockArray = NULL;
/* shared counter for dynamic allocation of LWLockIds */
static int *LWLockCounter;
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index effe5ac5246..a4bab87e24d 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.140 2003/12/12 18:45:09 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.141 2003/12/20 17:31:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -66,7 +66,7 @@ PGPROC *MyProc = NULL;
* relatively infrequently (only at backend startup or shutdown) and not for
* very long, so a spinlock is okay.
*/
-static slock_t *ProcStructLock = NULL;
+NON_EXEC_STATIC slock_t *ProcStructLock = NULL;
static PROC_HDR *ProcGlobal = NULL;
@@ -248,6 +248,7 @@ InitProcess(void)
MyProc->waitHolder = NULL;
SHMQueueInit(&(MyProc->procHolders));
+
/*
* Arrange to clean up at backend exit.
*/