PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <poll.h>
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
#include "portability/instr_time.h"
#include "postmaster/postmaster.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/pmsignal.h"
#include "utils/memutils.h"
#include "utils/resowner.h"
Go to the source code of this file.
Data Structures | |
struct | WaitEventSet |
Macros | |
#define | WAIT_USE_POLL |
#define | WAIT_USE_SELF_PIPE |
#define | LatchWaitSetLatchPos 0 |
Variables | |
static WaitEventSet * | LatchWaitSet |
static volatile sig_atomic_t | waiting = false |
static int | selfpipe_readfd = -1 |
static int | selfpipe_writefd = -1 |
static int | selfpipe_owner_pid = 0 |
static const ResourceOwnerDesc | wait_event_set_resowner_desc |
int AddWaitEventToSet | ( | WaitEventSet * | set, |
uint32 | events, | ||
pgsocket | fd, | ||
Latch * | latch, | ||
void * | user_data | ||
) |
Definition at line 963 of file latch.c.
References Assert, elog, ERROR, WaitEventSet::events, WaitEventSet::exit_on_postmaster_death, fd(), WaitEventSet::latch, WaitEventSet::latch_pos, MyProcPid, WaitEventSet::nevents, WaitEventSet::nevents_space, Latch::owner_pid, PGINVALID_SOCKET, WaitEvent::pos, postmaster_alive_fds, POSTMASTER_FD_WATCH, selfpipe_readfd, WaitEventAdjustPoll(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_MASK.
Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), InitializeLatchWaitSet(), postgresForeignAsyncConfigureWait(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().
WaitEventSet* CreateWaitEventSet | ( | ResourceOwner | resowner, |
int | nevents | ||
) |
Definition at line 751 of file latch.c.
References AcquireExternalFD(), close, data, elog, ERROR, WaitEventSet::events, WaitEventSet::exit_on_postmaster_death, WaitEventSet::latch, MAXALIGN, MemoryContextAllocZero(), WaitEventSet::nevents_space, WaitEventSet::owner, pgwin32_signal_event, WaitEventSet::pollfds, ReleaseExternalFD(), ResourceOwnerEnlarge(), ResourceOwnerRememberWaitEventSet(), StaticAssertStmt, and TopMemoryContext.
Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), InitializeLatchWaitSet(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().
void DisownLatch | ( | Latch * | latch | ) |
Definition at line 489 of file latch.c.
References Assert, Latch::is_shared, MyProcPid, and Latch::owner_pid.
Referenced by AuxiliaryProcKill(), ProcKill(), and ShutdownWalRecovery().
|
static |
Definition at line 2324 of file latch.c.
References buf, EAGAIN, EINTR, elog, ERROR, EWOULDBLOCK, fd(), read, selfpipe_readfd, and waiting.
Referenced by WaitEventSetWaitBlock().
void FreeWaitEventSet | ( | WaitEventSet * | set | ) |
Definition at line 874 of file latch.c.
References close, WaitEventSet::events, WaitEventSet::nevents, WaitEventSet::owner, pfree(), ReleaseExternalFD(), ResourceOwnerForgetWaitEventSet(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.
Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), ResOwnerReleaseWaitEventSet(), ShutdownLatchSupport(), and WaitLatchOrSocket().
void FreeWaitEventSetAfterFork | ( | WaitEventSet * | set | ) |
Definition at line 917 of file latch.c.
References close, pfree(), and ReleaseExternalFD().
Referenced by ClosePostmasterPorts().
int GetNumRegisteredWaitEvents | ( | WaitEventSet * | set | ) |
Definition at line 2262 of file latch.c.
References WaitEventSet::nevents.
Referenced by ExecAppendAsyncEventWait(), and postgresForeignAsyncConfigureWait().
void InitializeLatchSupport | ( | void | ) |
Definition at line 232 of file latch.c.
References Assert, close, elog, FATAL, IsUnderPostmaster, latch_sigurg_handler(), MyProcPid, pqsignal(), ReleaseExternalFD(), ReserveExternalFD(), selfpipe_owner_pid, selfpipe_readfd, selfpipe_writefd, SIG_IGN, and UnBlockSig.
Referenced by InitPostmasterChild(), InitStandaloneProcess(), and PostmasterMain().
void InitializeLatchWaitSet | ( | void | ) |
Definition at line 346 of file latch.c.
References AddWaitEventToSet(), Assert, CreateWaitEventSet(), IsUnderPostmaster, LatchWaitSet, LatchWaitSetLatchPos, MyLatch, PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, WL_EXIT_ON_PM_DEATH, and WL_LATCH_SET.
Referenced by InitPostmasterChild(), and InitStandaloneProcess().
void InitLatch | ( | Latch * | latch | ) |
Definition at line 394 of file latch.c.
References Assert, elog, ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, selfpipe_owner_pid, and selfpipe_readfd.
Referenced by InitProcessLocalLatch().
void InitSharedLatch | ( | Latch * | latch | ) |
Definition at line 430 of file latch.c.
References elog, ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, and Latch::owner_pid.
Referenced by InitProcGlobal(), and XLogRecoveryShmemInit().
|
static |
Definition at line 2275 of file latch.c.
References sendSelfPipeByte(), and waiting.
Referenced by InitializeLatchSupport().
void ModifyWaitEvent | ( | WaitEventSet * | set, |
int | pos, | ||
uint32 | events, | ||
Latch * | latch | ||
) |
Definition at line 1049 of file latch.c.
References Assert, elog, ERROR, WaitEventSet::events, WaitEvent::events, WaitEventSet::latch, MyProcPid, Latch::owner_pid, WaitEventAdjustPoll(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.
Referenced by pq_check_connection(), secure_read(), secure_write(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), WaitLatch(), and WalSndWait().
void OwnLatch | ( | Latch * | latch | ) |
Definition at line 463 of file latch.c.
References Assert, elog, Latch::is_shared, MyProcPid, Latch::owner_pid, PANIC, selfpipe_owner_pid, and selfpipe_readfd.
Referenced by InitAuxiliaryProcess(), InitProcess(), and InitWalRecovery().
void ResetLatch | ( | Latch * | latch | ) |
Definition at line 724 of file latch.c.
References Assert, Latch::is_set, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, and pg_memory_barrier.
Referenced by ApplyLauncherMain(), autoprewarm_main(), BackgroundWriterMain(), CheckpointerMain(), CheckpointWriteDelay(), ConditionVariableTimedSleep(), copy_read_data(), do_pg_backup_stop(), gather_readnext(), lazy_truncate_heap(), libpqrcv_connect(), libpqrcv_PQgetResult(), libpqsrv_cancel(), libpqsrv_connect_internal(), libpqsrv_get_result(), LogicalParallelApplyLoop(), logicalrep_worker_stop_internal(), LogicalRepApplyLoop(), mq_putmessage(), pa_send_data(), pa_wait_for_xact_state(), pg_promote(), pg_sleep(), pg_wait_until_termination(), pgarch_MainLoop(), pgfdw_get_cleanup_result(), pq_check_connection(), ProcessPendingWrites(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), secure_read(), secure_write(), ServerLoop(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), ShutDownSlotSync(), summarizer_wait_for_wal(), SyncRepWaitForLSN(), SysLoggerMain(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_slot_activity(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), WalReceiverMain(), WalSndLoop(), WalSndWaitForWal(), WalWriterMain(), and worker_spi_main().
|
inlinestatic |
Definition at line 219 of file latch.c.
References PointerGetDatum(), ResourceOwnerForget(), and wait_event_set_resowner_desc.
Referenced by FreeWaitEventSet().
|
inlinestatic |
Definition at line 214 of file latch.c.
References PointerGetDatum(), ResourceOwnerRemember(), and wait_event_set_resowner_desc.
Referenced by CreateWaitEventSet().
|
static |
Definition at line 2376 of file latch.c.
References Assert, DatumGetPointer(), FreeWaitEventSet(), WaitEventSet::owner, and res.
|
static |
Definition at line 2283 of file latch.c.
References EAGAIN, EINTR, EWOULDBLOCK, selfpipe_writefd, and write.
Referenced by latch_sigurg_handler(), and SetLatch().
void SetLatch | ( | Latch * | latch | ) |
Definition at line 632 of file latch.c.
References Latch::is_set, kill, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, pg_memory_barrier, sendSelfPipeByte(), and waiting.
Referenced by avl_sigusr2_handler(), CheckDeadLockAlert(), ClientCheckTimeoutHandler(), ConditionVariableBroadcast(), ConditionVariableSignal(), die(), ForwardSyncRequest(), handle_pm_child_exit_signal(), handle_pm_pmsignal_signal(), handle_pm_reload_request_signal(), handle_pm_shutdown_request_signal(), handle_sig_alarm(), HandleCatchupInterrupt(), HandleNotifyInterrupt(), HandleParallelApplyMessageInterrupt(), HandleParallelMessageInterrupt(), IdleInTransactionSessionTimeoutHandler(), IdleSessionTimeoutHandler(), IdleStatsUpdateTimeoutHandler(), logicalrep_worker_wakeup_ptr(), pgarch_waken_stop(), PgArchWakeup(), ProcessClientReadInterrupt(), ProcessClientWriteInterrupt(), ProcessPendingWrites(), ProcSendSignal(), procsignal_sigusr1_handler(), ProcWakeup(), ReqCheckpointHandler(), RequestXLogStreaming(), shm_mq_detach_internal(), shm_mq_inc_bytes_read(), shm_mq_send_bytes(), shm_mq_sendv(), shm_mq_set_receiver(), shm_mq_set_sender(), SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), sigUsr1Handler(), StatementCancelHandler(), StrategyGetBuffer(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), SyncRepWakeQueue(), test_shm_mq_main(), TransactionTimeoutHandler(), WakeupRecovery(), WakeupWalSummarizer(), WalRcvForceReply(), WalSndLastCycleHandler(), WalSndWaitForWal(), and XLogSetAsyncXactLSN().
void ShutdownLatchSupport | ( | void | ) |
Definition at line 364 of file latch.c.
References close, FreeWaitEventSet(), InvalidPid, LatchWaitSet, pqsignal(), selfpipe_owner_pid, selfpipe_readfd, selfpipe_writefd, and SIG_IGN.
|
static |
Definition at line 1176 of file latch.c.
References Assert, WaitEvent::events, WaitEvent::fd, WaitEventSet::latch, PGINVALID_SOCKET, WaitEventSet::pollfds, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_CLOSED, WL_SOCKET_READABLE, and WL_SOCKET_WRITEABLE.
Referenced by AddWaitEventToSet(), and ModifyWaitEvent().
bool WaitEventSetCanReportClosed | ( | void | ) |
int WaitEventSetWait | ( | WaitEventSet * | set, |
long | timeout, | ||
WaitEvent * | occurred_events, | ||
int | nevents, | ||
uint32 | wait_event_info | ||
) |
Definition at line 1424 of file latch.c.
References Assert, WaitEventSet::events, WaitEvent::events, WaitEvent::fd, INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, INSTR_TIME_SUBTRACT, Latch::is_set, WaitEventSet::latch, WaitEventSet::latch_pos, Latch::maybe_sleeping, pg_memory_barrier, PGINVALID_SOCKET, pgstat_report_wait_end(), pgstat_report_wait_start(), pgwin32_dispatch_queued_signals(), WaitEvent::pos, start_time, WaitEvent::user_data, WaitEventSetWaitBlock(), waiting, and WL_LATCH_SET.
Referenced by ExecAppendAsyncEventWait(), pq_check_connection(), secure_read(), secure_write(), ServerLoop(), SysLoggerMain(), WaitLatch(), WaitLatchOrSocket(), and WalSndWait().
|
inlinestatic |
Definition at line 1850 of file latch.c.
References Assert, drain(), EINTR, ereport, errcode_for_socket_access(), errmsg(), ERROR, WaitEventSet::events, WaitEvent::events, WaitEventSet::exit_on_postmaster_death, WaitEvent::fd, Latch::is_set, WaitEventSet::latch, WaitEventSet::nevents, PGINVALID_SOCKET, WaitEventSet::pollfds, WaitEvent::pos, PostmasterIsAliveInternal(), proc_exit(), WaitEvent::user_data, waiting, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_CLOSED, WL_SOCKET_READABLE, and WL_SOCKET_WRITEABLE.
Referenced by WaitEventSetWait().
Definition at line 517 of file latch.c.
References Assert, WaitEventSet::exit_on_postmaster_death, IsUnderPostmaster, LatchWaitSet, LatchWaitSetLatchPos, ModifyWaitEvent(), WaitEventSetWait(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.
Referenced by ApplyLauncherMain(), autoprewarm_main(), BackgroundWriterMain(), CheckpointerMain(), CheckpointWriteDelay(), ConditionVariableTimedSleep(), do_pg_backup_stop(), gather_readnext(), lazy_truncate_heap(), LogicalParallelApplyLoop(), logicalrep_worker_stop_internal(), mq_putmessage(), pa_send_data(), pa_wait_for_xact_state(), pg_promote(), pg_sleep(), pg_wait_until_termination(), pgarch_MainLoop(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), RegisterSyncRequest(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), ShutDownSlotSync(), summarizer_wait_for_wal(), SyncRepWaitForLSN(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_slot_activity(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), WalSummarizerMain(), WalWriterMain(), and worker_spi_main().
int WaitLatchOrSocket | ( | Latch * | latch, |
int | wakeEvents, | ||
pgsocket | sock, | ||
long | timeout, | ||
uint32 | wait_event_info | ||
) |
Definition at line 565 of file latch.c.
References AddWaitEventToSet(), Assert, CreateWaitEventSet(), CurrentResourceOwner, FreeWaitEventSet(), IsUnderPostmaster, PGINVALID_SOCKET, WaitEventSetWait(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_MASK, and WL_TIMEOUT.
Referenced by be_tls_open_server(), copy_read_data(), libpqrcv_connect(), libpqrcv_PQgetResult(), libpqsrv_cancel(), libpqsrv_connect_internal(), libpqsrv_get_result(), LogicalRepApplyLoop(), pgfdw_get_cleanup_result(), read_or_wait(), secure_open_gssapi(), and WalReceiverMain().
|
static |
Definition at line 155 of file latch.c.
Referenced by InitializeLatchWaitSet(), ShutdownLatchSupport(), and WaitLatch().
|
static |
Definition at line 176 of file latch.c.
Referenced by InitializeLatchSupport(), InitLatch(), OwnLatch(), and ShutdownLatchSupport().
|
static |
Definition at line 172 of file latch.c.
Referenced by AddWaitEventToSet(), drain(), InitializeLatchSupport(), InitLatch(), OwnLatch(), and ShutdownLatchSupport().
|
static |
Definition at line 173 of file latch.c.
Referenced by InitializeLatchSupport(), sendSelfPipeByte(), and ShutdownLatchSupport().
|
static |
Definition at line 203 of file latch.c.
Referenced by ResourceOwnerForgetWaitEventSet(), and ResourceOwnerRememberWaitEventSet().
|
static |
Definition at line 162 of file latch.c.
Referenced by drain(), latch_sigurg_handler(), LockBufferForCleanup(), ResolveRecoveryConflictWithVirtualXIDs(), run_permutation(), SetLatch(), try_complete_step(), try_complete_steps(), WaitEventSetWait(), and WaitEventSetWaitBlock().