diff options
Diffstat (limited to 'src/backend/storage/ipc/ipci.c')
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 716963f4481..bf232eb8dc6 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.88 2006/10/04 00:29:57 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.89 2006/10/15 22:04:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -32,6 +32,30 @@ #include "storage/spin.h" +static Size total_addin_request = 0; +static bool addin_request_allowed = true; + + +/* + * RequestAddinShmemSpace + * Request that extra shmem space be allocated for use by + * a loadable module. + * + * This is only useful if called from the _PG_init hook of a library that + * is loaded into the postmaster via shared_preload_libraries. Once + * shared memory has been allocated, calls will be ignored. (We could + * raise an error, but it seems better to make it a no-op, so that + * libraries containing such calls can be reloaded if needed.) + */ +void +RequestAddinShmemSpace(Size size) +{ + if (IsUnderPostmaster || !addin_request_allowed) + return; /* too late */ + total_addin_request = add_size(total_addin_request, size); +} + + /* * CreateSharedMemoryAndSemaphores * Creates and initializes shared memory and semaphores. @@ -57,7 +81,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) { PGShmemHeader *seghdr; Size size; - Size size_b4addins; int numSemas; /* @@ -91,16 +114,11 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) size = add_size(size, ShmemBackendArraySize()); #endif - /* might as well round it off to a multiple of a typical page size */ - size = add_size(size, 8192 - (size % 8192)); + /* freeze the addin request size and include it */ + addin_request_allowed = false; + size = add_size(size, total_addin_request); - /* - * The shared memory for add-ins is treated as a separate segment, but - * in reality it is not. - */ - size_b4addins = size; - size = add_size(size, AddinShmemSize()); - /* round it off again */ + /* might as well round it off to a multiple of a typical page size */ size = add_size(size, 8192 - (size % 8192)); elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)", @@ -111,16 +129,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) */ seghdr = PGSharedMemoryCreate(size, makePrivate, port); - /* - * Modify hdr to show segment size before add-ins - */ - seghdr->totalsize = size_b4addins; - - /* - * Set up segment header sections in each Addin context - */ - InitAddinContexts((void *) ((char *) seghdr + size_b4addins)); - InitShmemAccess(seghdr); /* |