diff options
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/Makefile | 4 | ||||
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 8 | ||||
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 86 | ||||
-rw-r--r-- | src/backend/storage/ipc/sinvaladt.c | 18 |
4 files changed, 103 insertions, 13 deletions
diff --git a/src/backend/storage/ipc/Makefile b/src/backend/storage/ipc/Makefile index 585ae7f6eff..960097b1d18 100644 --- a/src/backend/storage/ipc/Makefile +++ b/src/backend/storage/ipc/Makefile @@ -1,7 +1,7 @@ # # Makefile for storage/ipc # -# $Header: /cvsroot/pgsql/src/backend/storage/ipc/Makefile,v 1.16 2001/09/27 19:10:02 tgl Exp $ +# $Header: /cvsroot/pgsql/src/backend/storage/ipc/Makefile,v 1.17 2001/11/04 19:55:31 tgl Exp $ # subdir = src/backend/storage/ipc @@ -15,7 +15,7 @@ override CFLAGS+= -fno-inline endif endif -OBJS = ipc.o ipci.o shmem.o shmqueue.o sinval.o sinvaladt.o +OBJS = ipc.o ipci.o pmsignal.o shmem.o shmqueue.o sinval.o sinvaladt.o all: SUBSYS.o diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index cf841a614d3..9b178883fe4 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.44 2001/10/25 05:49:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.45 2001/11/04 19:55:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -23,6 +23,7 @@ #include "storage/freespace.h" #include "storage/lmgr.h" #include "storage/lwlock.h" +#include "storage/pmsignal.h" #include "storage/proc.h" #include "storage/sinval.h" #include "storage/spin.h" @@ -121,4 +122,9 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int maxBackends) * Set up free-space map */ InitFreeSpaceMap(); + + /* + * Set up child-to-postmaster signaling mechanism + */ + PMSignalInit(); } diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c new file mode 100644 index 00000000000..38c5d730c7f --- /dev/null +++ b/src/backend/storage/ipc/pmsignal.c @@ -0,0 +1,86 @@ +/*------------------------------------------------------------------------- + * + * pmsignal.c + * routines for signaling the postmaster from its child processes + * + * + * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/pmsignal.c,v 1.1 2001/11/04 19:55:31 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include <signal.h> +#include <unistd.h> + +#include "miscadmin.h" +#include "storage/pmsignal.h" +#include "storage/shmem.h" + + +/* + * The postmaster is signaled by its children by sending SIGUSR1. The + * specific reason is communicated via flags in shared memory. We keep + * a boolean flag for each possible "reason", so that different reasons + * can be signaled by different backends at the same time. (However, + * if the same reason is signaled more than once simultaneously, the + * postmaster will observe it only once.) + * + * The flags are actually declared as "volatile sig_atomic_t" for maximum + * portability. This should ensure that loads and stores of the flag + * values are atomic, allowing us to dispense with any explicit locking. + */ + +static volatile sig_atomic_t * PMSignalFlags; + + +/* + * PMSignalInit - initialize during shared-memory creation + */ +void +PMSignalInit(void) +{ + /* Should be called only once */ + Assert(!PMSignalFlags); + + PMSignalFlags = (sig_atomic_t *) + ShmemAlloc(NUM_PMSIGNALS * sizeof(sig_atomic_t)); + + MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t)); +} + +/* + * SendPostmasterSignal - signal the postmaster from a child process + */ +void +SendPostmasterSignal(PMSignalReason reason) +{ + /* If called in a standalone backend, do nothing */ + if (!IsUnderPostmaster) + return; + /* Atomically set the proper flag */ + PMSignalFlags[reason] = true; + /* Send signal to postmaster (assume it is our direct parent) */ + kill(getppid(), SIGUSR1); +} + +/* + * CheckPostmasterSignal - check to see if a particular reason has been + * signaled, and clear the signal flag. Should be called by postmaster + * after receiving SIGUSR1. + */ +bool +CheckPostmasterSignal(PMSignalReason reason) +{ + /* Careful here --- don't clear flag if we haven't seen it set */ + if (PMSignalFlags[reason]) + { + PMSignalFlags[reason] = false; + return true; + } + return false; +} diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c index d05a651097f..35931f00a14 100644 --- a/src/backend/storage/ipc/sinvaladt.c +++ b/src/backend/storage/ipc/sinvaladt.c @@ -8,17 +8,15 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.41 2001/09/29 04:02:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.42 2001/11/04 19:55:31 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" -#include <signal.h> -#include <unistd.h> - #include "miscadmin.h" #include "storage/backendid.h" +#include "storage/pmsignal.h" #include "storage/proc.h" #include "storage/sinvaladt.h" @@ -205,11 +203,11 @@ SIInsertDataEntry(SISeg *segP, SharedInvalidationMessage *data) /* * Try to prevent table overflow. When the table is 70% full send a - * SIGUSR2 (ordinarily a NOTIFY signal) to the postmaster, which will - * send it back to all the backends. This will force idle backends to - * execute a transaction to look through pg_listener for NOTIFY - * messages, and as a byproduct of the transaction start they will - * read SI entries. + * WAKEN_CHILDREN request to the postmaster. The postmaster will send + * a SIGUSR2 signal (ordinarily a NOTIFY signal) to all the backends. + * This will force idle backends to execute a transaction to look through + * pg_listener for NOTIFY messages, and as a byproduct of the transaction + * start they will read SI entries. * * This should never happen if all the backends are actively executing * queries, but if a backend is sitting idle then it won't be starting @@ -222,7 +220,7 @@ SIInsertDataEntry(SISeg *segP, SharedInvalidationMessage *data) { if (DebugLvl >= 1) elog(DEBUG, "SIInsertDataEntry: table is 70%% full, signaling postmaster"); - kill(getppid(), SIGUSR2); + SendPostmasterSignal(PMSIGNAL_WAKEN_CHILDREN); } /* |