Go to the source code of this file.
Defines | |
#define | PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) |
#define | PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) |
Typedefs | |
typedef void(* | pg_on_exit_callback )(int code, Datum arg) |
typedef void(* | shmem_startup_hook_type )(void) |
Functions | |
void | proc_exit (int code) __attribute__((noreturn)) |
void | shmem_exit (int code) |
void | on_proc_exit (pg_on_exit_callback function, Datum arg) |
void | on_shmem_exit (pg_on_exit_callback function, Datum arg) |
void | cancel_shmem_exit (pg_on_exit_callback function, Datum arg) |
void | on_exit_reset (void) |
void | CreateSharedMemoryAndSemaphores (bool makePrivate, int port) |
Variables | |
bool | proc_exit_inprogress |
PGDLLIMPORT shmem_startup_hook_type | shmem_startup_hook |
#define PG_END_ENSURE_ERROR_CLEANUP | ( | cleanup_function, | ||
arg | ||||
) |
cancel_shmem_exit(cleanup_function, arg); \ PG_CATCH(); \ { \ cancel_shmem_exit(cleanup_function, arg); \ cleanup_function (0, arg); \ PG_RE_THROW(); \ } \ PG_END_TRY(); \ } while (0)
Definition at line 52 of file ipc.h.
Referenced by btbulkdelete(), createdb(), do_pg_start_backup(), movedb(), and perform_base_backup().
#define PG_ENSURE_ERROR_CLEANUP | ( | cleanup_function, | ||
arg | ||||
) |
do { \ on_shmem_exit(cleanup_function, arg); \ PG_TRY()
Definition at line 47 of file ipc.h.
Referenced by btbulkdelete(), createdb(), do_pg_start_backup(), movedb(), and perform_base_backup().
typedef void(* pg_on_exit_callback)(int code, Datum arg) |
typedef void(* shmem_startup_hook_type)(void) |
void cancel_shmem_exit | ( | pg_on_exit_callback | function, | |
Datum | arg | |||
) |
Definition at line 309 of file ipc.c.
References on_shmem_exit_index, and on_shmem_exit_list.
{ if (on_shmem_exit_index > 0 && on_shmem_exit_list[on_shmem_exit_index - 1].function == function && on_shmem_exit_list[on_shmem_exit_index - 1].arg == arg) --on_shmem_exit_index; }
void CreateSharedMemoryAndSemaphores | ( | bool | makePrivate, | |
int | port | |||
) |
Definition at line 88 of file ipci.c.
References add_size(), addin_request_allowed, Assert, AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemInit(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BTreeShmemInit(), BTreeShmemSize(), BufferShmemSize(), CheckpointerShmemInit(), CheckpointerShmemSize(), CLOGShmemInit(), CLOGShmemSize(), CreateLWLocks(), CreateSharedBackendStatus(), CreateSharedInvalidationState(), CreateSharedProcArray(), DEBUG3, elog, hash_estimate_size(), InitBufferPool(), InitLocks(), InitPredicateLocks(), InitProcGlobal(), InitShmemAccess(), InitShmemAllocation(), InitShmemIndex(), IsUnderPostmaster, LockShmemSize(), LWLockShmemSize(), MultiXactShmemInit(), MultiXactShmemSize(), PANIC, PGReserveSemaphores(), PGSharedMemoryCreate(), PMSignalShmemInit(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalSemas(), ProcGlobalShmemSize(), ProcSignalShmemInit(), ProcSignalShmemSize(), SHMEM_INDEX_SIZE, shmem_startup_hook, SInvalShmemSize(), SpinlockSemas(), SUBTRANSShmemInit(), SUBTRANSShmemSize(), SyncScanShmemInit(), SyncScanShmemSize(), total_addin_request, TwoPhaseShmemInit(), TwoPhaseShmemSize(), WalRcvShmemInit(), WalRcvShmemSize(), WalSndShmemInit(), WalSndShmemSize(), XLOGShmemInit(), and XLOGShmemSize().
Referenced by InitCommunication(), and reset_shared().
{ if (!IsUnderPostmaster) { PGShmemHeader *seghdr; Size size; int numSemas; /* * Size of the Postgres shared-memory block is estimated via * moderately-accurate estimates for the big hogs, plus 100K for the * stuff that's too small to bother with estimating. * * We take some care during this phase to ensure that the total size * request doesn't overflow size_t. If this gets through, we don't * need to be so careful during the actual allocation phase. */ size = 100000; size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt))); size = add_size(size, BufferShmemSize()); size = add_size(size, LockShmemSize()); size = add_size(size, PredicateLockShmemSize()); size = add_size(size, ProcGlobalShmemSize()); size = add_size(size, XLOGShmemSize()); size = add_size(size, CLOGShmemSize()); size = add_size(size, SUBTRANSShmemSize()); size = add_size(size, TwoPhaseShmemSize()); size = add_size(size, MultiXactShmemSize()); size = add_size(size, LWLockShmemSize()); size = add_size(size, ProcArrayShmemSize()); size = add_size(size, BackendStatusShmemSize()); size = add_size(size, SInvalShmemSize()); size = add_size(size, PMSignalShmemSize()); size = add_size(size, ProcSignalShmemSize()); size = add_size(size, CheckpointerShmemSize()); size = add_size(size, AutoVacuumShmemSize()); size = add_size(size, WalSndShmemSize()); size = add_size(size, WalRcvShmemSize()); size = add_size(size, BTreeShmemSize()); size = add_size(size, SyncScanShmemSize()); size = add_size(size, AsyncShmemSize()); #ifdef EXEC_BACKEND size = add_size(size, ShmemBackendArraySize()); #endif /* freeze the addin request size and include it */ addin_request_allowed = false; size = add_size(size, total_addin_request); /* 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)", (unsigned long) size); /* * Create the shmem segment */ seghdr = PGSharedMemoryCreate(size, makePrivate, port); InitShmemAccess(seghdr); /* * Create semaphores */ numSemas = ProcGlobalSemas(); numSemas += SpinlockSemas(); PGReserveSemaphores(numSemas, port); } else { /* * We are reattaching to an existing shared memory segment. This * should only be reached in the EXEC_BACKEND case, and even then only * with makePrivate == false. */ #ifdef EXEC_BACKEND Assert(!makePrivate); #else elog(PANIC, "should be attached to shared memory already"); #endif } /* * Set up shared memory allocation mechanism */ if (!IsUnderPostmaster) InitShmemAllocation(); /* * Now initialize LWLocks, which do shared memory allocation and are * needed for InitShmemIndex. */ if (!IsUnderPostmaster) CreateLWLocks(); /* * Set up shmem.c index hashtable */ InitShmemIndex(); /* * Set up xlog, clog, and buffers */ XLOGShmemInit(); CLOGShmemInit(); SUBTRANSShmemInit(); MultiXactShmemInit(); InitBufferPool(); /* * Set up lock manager */ InitLocks(); /* * Set up predicate lock manager */ InitPredicateLocks(); /* * Set up process table */ if (!IsUnderPostmaster) InitProcGlobal(); CreateSharedProcArray(); CreateSharedBackendStatus(); TwoPhaseShmemInit(); /* * Set up shared-inval messaging */ CreateSharedInvalidationState(); /* * Set up interprocess signaling mechanisms */ PMSignalShmemInit(); ProcSignalShmemInit(); CheckpointerShmemInit(); AutoVacuumShmemInit(); WalSndShmemInit(); WalRcvShmemInit(); /* * Set up other modules that need some shared memory space */ BTreeShmemInit(); SyncScanShmemInit(); AsyncShmemInit(); #ifdef EXEC_BACKEND /* * Alloc the win32 shared backend array */ if (!IsUnderPostmaster) ShmemBackendArrayAllocation(); #endif /* * Now give loadable modules a chance to set up their shmem allocations */ if (shmem_startup_hook) shmem_startup_hook(); }
void on_exit_reset | ( | void | ) |
Definition at line 100 of file ipc_test.c.
References on_proc_exit_index, and on_shmem_exit_index.
Referenced by BackendStartup(), bg_quickdie(), bgworker_quickdie(), chkpt_quickdie(), main(), pgarch_start(), pgstat_start(), quickdie(), start_bgworker(), StartAutoVacLauncher(), StartAutoVacWorker(), StartChildProcess(), startupproc_quickdie(), SysLogger_Start(), wal_quickdie(), and WalRcvQuickDieHandler().
{ on_shmem_exit_index = 0; on_proc_exit_index = 0; }
void on_proc_exit | ( | pg_on_exit_callback | function, | |
Datum | arg | |||
) |
Definition at line 253 of file ipc.c.
References ONEXIT::arg, atexit_callback(), atexit_callback_setup, ereport, errcode(), errmsg_internal(), FATAL, ONEXIT::function, MAX_ON_EXITS, on_proc_exit_index, and on_proc_exit_list.
Referenced by CreateLockFile(), InitCatCache(), InitFileAccess(), PostgresMain(), PostmasterMain(), pq_init(), select_perl_context(), sepgsql_avc_init(), and smgrinit().
{ if (on_proc_exit_index >= MAX_ON_EXITS) ereport(FATAL, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg_internal("out of on_proc_exit slots"))); on_proc_exit_list[on_proc_exit_index].function = function; on_proc_exit_list[on_proc_exit_index].arg = arg; ++on_proc_exit_index; if (!atexit_callback_setup) { atexit(atexit_callback); atexit_callback_setup = true; } }
void on_shmem_exit | ( | pg_on_exit_callback | function, | |
Datum | arg | |||
) |
Definition at line 88 of file ipc_test.c.
References ONEXIT::arg, atexit_callback(), atexit_callback_setup, elog, ereport, errcode(), errmsg_internal(), FATAL, ONEXIT::function, MAX_ON_EXITS, on_shmem_exit_index, and on_shmem_exit_list.
Referenced by AtEOXact_Namespace(), AutoVacWorkerMain(), AuxiliaryProcessMain(), Exec_ListenPreCommit(), InitAuxiliaryProcess(), InitBufferPoolBackend(), InitPostgres(), InitProcess(), InitProcessPhase2(), InitWalSenderSlot(), InternalIpcMemoryCreate(), PGReserveSemaphores(), PGSharedMemoryCreate(), pgss_shmem_startup(), pgstat_initialize(), ProcSignalInit(), SharedInvalBackendInit(), and WalReceiverMain().
{ if (on_shmem_exit_index >= MAX_ON_EXITS) elog(FATAL, "out of on_shmem_exit slots"); on_shmem_exit_list[on_shmem_exit_index].function = function; on_shmem_exit_list[on_shmem_exit_index].arg = arg; ++on_shmem_exit_index; }
void proc_exit | ( | int | code | ) |
Definition at line 69 of file ipc_test.c.
References arg, DEBUG3, elog, ONEXIT::function, IsAutoVacuumWorkerProcess(), mkdir, on_proc_exit_index, on_proc_exit_list, proc_exit_prepare(), S_IRWXG, S_IRWXO, shmem_exit(), and snprintf().
Referenced by auth_failed(), AutoVacLauncherMain(), AutoVacWorkerMain(), AuxiliaryProcessMain(), BackendInitialize(), BackgroundWriterMain(), BootstrapModeMain(), CheckerModeMain(), CheckpointerMain(), do_start_bgworker(), elog_finish(), errfinish(), ExitPostmaster(), HandleStartupProcInterrupts(), main(), PostgresMain(), PreRestoreCommand(), ProcessRepliesIfAny(), ProcessStandbyMessage(), RestoreArchivedFile(), StartReplication(), startup_die(), StartupPacketTimeoutHandler(), StartupProcessMain(), StartupProcShutdownHandler(), SysLoggerMain(), WalRcvWaitForStartPosition(), WalReceiverMain(), WalSndErrorCleanup(), WalSndLoop(), WalWriterMain(), and worker_spi_main().
{ shmem_exit(code); while (--on_proc_exit_index >= 0) (*on_proc_exit_list[on_proc_exit_index].function) (code, on_proc_exit_list[on_proc_exit_index].arg); exit(code); }
void shmem_exit | ( | int | code | ) |
Definition at line 79 of file ipc_test.c.
References arg, DEBUG3, elog, ONEXIT::function, on_shmem_exit_index, and on_shmem_exit_list.
Referenced by main(), PostmasterStateMachine(), proc_exit(), and proc_exit_prepare().
{ while (--on_shmem_exit_index >= 0) (*on_shmem_exit_list[on_shmem_exit_index].function) (code, on_shmem_exit_list[on_shmem_exit_index].arg); on_shmem_exit_index = 0; }
Definition at line 39 of file ipc.c.
Referenced by die(), errstart(), HandleCatchupInterrupt(), HandleNotifyInterrupt(), proc_exit_prepare(), RecoveryConflictInterrupt(), StatementCancelHandler(), and WalRcvShutdownHandler().
PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook |
Definition at line 43 of file ipci.c.
Referenced by _PG_fini(), _PG_init(), and CreateSharedMemoryAndSemaphores().