diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-28 05:13:32 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-28 05:13:32 +0000 |
commit | 1a321f26d88e5c64bccba9d36920aede1e201729 (patch) | |
tree | 43940a3ed5cc754bff68748502550731b0ad19a0 /src/backend/storage | |
parent | 37da0ba0e0f2d92857dc62789820d21e177dc00f (diff) | |
download | postgresql-1a321f26d88e5c64bccba9d36920aede1e201729.tar.gz postgresql-1a321f26d88e5c64bccba9d36920aede1e201729.zip |
Code review for EXEC_BACKEND changes. Reduce the number of #ifdefs by
about a third, make it work on non-Windows platforms again. (But perhaps
I broke the WIN32 code, since I have no way to test that.) Fold all the
paths that fork postmaster child processes to go through the single
routine SubPostmasterMain, which takes care of resurrecting the state that
would normally be inherited from the postmaster (including GUC variables).
Clean up some places where there's no particularly good reason for the
EXEC and non-EXEC cases to work differently. Take care of one or two
FIXMEs that remained in the code.
Diffstat (limited to 'src/backend/storage')
-rw-r--r-- | src/backend/storage/buffer/buf_init.c | 24 | ||||
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 18 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lmgr.c | 9 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 34 |
4 files changed, 41 insertions, 44 deletions
diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index 440b25ae512..25656f74448 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.65 2004/04/22 07:21:55 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.66 2004/05/28 05:13:01 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -93,15 +93,6 @@ InitBufferPool(void) foundDescs; int i; - /* - * It's probably not really necessary to grab the lock --- if there's - * 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", NBuffers * sizeof(BufferDesc), &foundDescs); @@ -120,6 +111,13 @@ InitBufferPool(void) BufferDesc *buf; char *block; + /* + * It's probably not really necessary to grab the lock --- if there's + * anyone else attached to the shmem at this point, we've got + * problems. + */ + LWLockAcquire(BufMgrLock, LW_EXCLUSIVE); + buf = BufferDescriptors; block = BufferBlocks; @@ -147,14 +145,12 @@ InitBufferPool(void) /* Correct last entry */ BufferDescriptors[NBuffers - 1].bufNext = -1; + + LWLockRelease(BufMgrLock); } /* Init other shared buffer-management stuff */ StrategyInitialize(!foundDescs); - -#ifndef EXEC_BACKEND - LWLockRelease(BufMgrLock); -#endif } /* diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 3e8c2a6c1b6..4ce5c98b577 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.66 2004/04/19 23:27:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.67 2004/05/28 05:13:03 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -37,9 +37,13 @@ * * This is called by the postmaster or by a standalone backend. * It is also called by a backend forked from the postmaster under - * the EXEC_BACKEND case - * - * In the non EXEC_BACKEND case, backends already have shared memory ready-to-go. + * the EXEC_BACKEND case. (In the non EXEC_BACKEND case, backends + * start life already attached to shared memory.) The initialization + * functions are set up to simply "attach" to pre-existing shared memory + * structures in the latter case. We have to do that in order to + * initialize pointers in local memory that reference the shared structures. + * (In the non EXEC_BACKEND case, these pointer values are inherited via + * fork() from the postmaster.) * * If "makePrivate" is true then we only need private memory, not shared * memory. This is true for a standalone backend, false for a postmaster. @@ -96,8 +100,12 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, * (this should only ever be reached by EXEC_BACKEND code, * and only then with makePrivate == false) */ - Assert(ExecBackend && !makePrivate); +#ifdef EXEC_BACKEND + Assert(!makePrivate); seghdr = PGSharedMemoryCreate(-1, makePrivate, 0); +#else + Assert(false); +#endif } diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 41e2df3a9be..e4e52b16abf 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.62 2003/12/01 21:59:25 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.63 2004/05/28 05:13:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -75,6 +75,13 @@ InitLockTable(int maxBackends) { LOCKMETHODID LongTermTableId; + /* there's no zero-th table */ + NumLockMethods = 1; + + /* + * Create the default lock method table + */ + /* number of lock modes is lengthof()-1 because of dummy zero */ LockTableId = LockMethodTableInit("LockTable", LockConflicts, diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 8cb25b4ccdd..88179a0731a 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.131 2003/12/20 17:31:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.132 2004/05/28 05:13:05 tgl Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -155,7 +155,9 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP) static LockMethod LockMethods[MAX_LOCK_METHODS]; static HTAB* LockMethodLockHash[MAX_LOCK_METHODS]; static HTAB* LockMethodProcLockHash[MAX_LOCK_METHODS]; -static int NumLockMethods; + +/* exported so lmgr.c can initialize it */ +int NumLockMethods; /* @@ -190,15 +192,15 @@ GetLocksMethodTable(LOCK *lock) */ static void LockMethodInit(LockMethod lockMethodTable, - LOCKMASK *conflictsP, + const LOCKMASK *conflictsP, int numModes) { int i; lockMethodTable->numLockModes = numModes; /* copies useless zero element as well as the N lockmodes */ - for (i = 0; i <= numModes; i++, conflictsP++) - lockMethodTable->conflictTab[i] = *conflictsP; + for (i = 0; i <= numModes; i++) + lockMethodTable->conflictTab[i] = conflictsP[i]; } /* @@ -211,8 +213,8 @@ LockMethodInit(LockMethod lockMethodTable, * TopMemoryContext. */ LOCKMETHODID -LockMethodTableInit(char *tabName, - LOCKMASK *conflictsP, +LockMethodTableInit(const char *tabName, + const LOCKMASK *conflictsP, int numModes, int maxBackends) { @@ -245,17 +247,6 @@ LockMethodTableInit(char *tabName, elog(FATAL, "could not initialize lock table \"%s\"", tabName); /* - * Lock the LWLock for the table (probably not necessary here) - */ -#ifndef EXEC_BACKEND - LWLockAcquire(LockMgrLock, LW_EXCLUSIVE); -#endif - /* - * no zero-th table - */ - NumLockMethods = 1; - - /* * we're first - initialize */ if (!found) @@ -263,6 +254,7 @@ LockMethodTableInit(char *tabName, MemSet(newLockMethod, 0, sizeof(LockMethodData)); newLockMethod->masterLock = LockMgrLock; newLockMethod->lockmethodid = NumLockMethods; + LockMethodInit(newLockMethod, conflictsP, numModes); } /* @@ -311,12 +303,6 @@ LockMethodTableInit(char *tabName, 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; |