diff options
author | Jan Wieck <JanWieck@Yahoo.com> | 2003-11-19 15:55:08 +0000 |
---|---|---|
committer | Jan Wieck <JanWieck@Yahoo.com> | 2003-11-19 15:55:08 +0000 |
commit | cfeca62148582a05466362f1957572f5a9900ab5 (patch) | |
tree | 6a2c5086a40d410ceb8555d8f94b7f5492979283 /src/backend/storage/lmgr/proc.c | |
parent | 5032f83082e5bdb37f8dbf02fa00c4886fb6d2ce (diff) | |
download | postgresql-cfeca62148582a05466362f1957572f5a9900ab5.tar.gz postgresql-cfeca62148582a05466362f1957572f5a9900ab5.zip |
Background writer process
This first part of the background writer does no syncing at all.
It's only purpose is to keep the LRU heads clean so that regular
backends seldom to never have to call write().
Jan
Diffstat (limited to 'src/backend/storage/lmgr/proc.c')
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 6ffac1d43cf..cea8ffe4c76 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.136 2003/10/16 20:59:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.137 2003/11/19 15:55:07 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -71,6 +71,7 @@ static slock_t *ProcStructLock = NULL; static PROC_HDR *ProcGlobal = NULL; static PGPROC *DummyProc = NULL; +static int dummy_proc_type = -1; static bool waitingForLock = false; static bool waitingForSignal = false; @@ -163,14 +164,17 @@ InitProcGlobal(int maxBackends) * processes, too. This does not get linked into the freeProcs * list. */ - DummyProc = (PGPROC *) ShmemAlloc(sizeof(PGPROC)); + DummyProc = (PGPROC *) ShmemAlloc(sizeof(PGPROC) * NUM_DUMMY_PROCS); if (!DummyProc) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"))); - MemSet(DummyProc, 0, sizeof(PGPROC)); - DummyProc->pid = 0; /* marks DummyProc as not in use */ - PGSemaphoreCreate(&DummyProc->sem); + MemSet(DummyProc, 0, sizeof(PGPROC) * NUM_DUMMY_PROCS); + for (i = 0; i < NUM_DUMMY_PROCS; i++) + { + DummyProc[i].pid = 0; /* marks DummyProc as not in use */ + PGSemaphoreCreate(&(DummyProc[i].sem)); + } /* Create ProcStructLock spinlock, too */ ProcStructLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); @@ -270,8 +274,10 @@ InitProcess(void) * sema that are assigned are the extra ones created during InitProcGlobal. */ void -InitDummyProcess(void) +InitDummyProcess(int proctype) { + PGPROC *dummyproc; + /* * ProcGlobal should be set by a previous call to InitProcGlobal (we * inherit this by fork() from the postmaster). @@ -282,12 +288,17 @@ InitDummyProcess(void) if (MyProc != NULL) elog(ERROR, "you already exist"); + Assert(dummy_proc_type < 0); + dummy_proc_type = proctype; + dummyproc = &DummyProc[proctype]; + /* - * DummyProc should not presently be in use by anyone else + * dummyproc should not presently be in use by anyone else */ - if (DummyProc->pid != 0) - elog(FATAL, "DummyProc is in use by PID %d", DummyProc->pid); - MyProc = DummyProc; + if (dummyproc->pid != 0) + elog(FATAL, "DummyProc[%d] is in use by PID %d", + proctype, dummyproc->pid); + MyProc = dummyproc; /* * Initialize all fields of MyProc, except MyProc->sem which was set @@ -310,7 +321,7 @@ InitDummyProcess(void) /* * Arrange to clean up at process exit. */ - on_shmem_exit(DummyProcKill, 0); + on_shmem_exit(DummyProcKill, proctype); /* * We might be reusing a semaphore that belonged to a failed process. @@ -446,7 +457,13 @@ ProcKill(void) static void DummyProcKill(void) { - Assert(MyProc != NULL && MyProc == DummyProc); + PGPROC *dummyproc; + + Assert(dummy_proc_type >= 0 && dummy_proc_type < NUM_DUMMY_PROCS); + + dummyproc = &DummyProc[dummy_proc_type]; + + Assert(MyProc != NULL && MyProc == dummyproc); /* Release any LW locks I am holding */ LWLockReleaseAll(); @@ -463,6 +480,8 @@ DummyProcKill(void) /* PGPROC struct isn't mine anymore */ MyProc = NULL; + + dummy_proc_type = -1; } |