PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <unistd.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 "storage/shmem.h"
#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
struct | WaitEventSet |
Macros | |
#define | LatchWaitSetLatchPos 0 |
Functions | |
static int | WaitEventSetWaitBlock (WaitEventSet *set, int cur_timeout, WaitEvent *occurred_events, int nevents) |
void | InitializeLatchSupport (void) |
void | InitializeLatchWaitSet (void) |
void | ShutdownLatchSupport (void) |
void | InitLatch (Latch *latch) |
void | InitSharedLatch (Latch *latch) |
void | OwnLatch (Latch *latch) |
void | DisownLatch (Latch *latch) |
int | WaitLatch (Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info) |
int | WaitLatchOrSocket (Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info) |
void | SetLatch (Latch *latch) |
void | ResetLatch (Latch *latch) |
WaitEventSet * | CreateWaitEventSet (MemoryContext context, int nevents) |
void | FreeWaitEventSet (WaitEventSet *set) |
int | AddWaitEventToSet (WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data) |
void | ModifyWaitEvent (WaitEventSet *set, int pos, uint32 events, Latch *latch) |
int | WaitEventSetWait (WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info) |
Variables | |
static WaitEventSet * | LatchWaitSet |
static volatile sig_atomic_t | waiting = false |
#define LatchWaitSetLatchPos 0 |
Definition at line 143 of file latch.c.
Referenced by InitializeLatchWaitSet(), and WaitLatch().
int AddWaitEventToSet | ( | WaitEventSet * | set, |
uint32 | events, | ||
pgsocket | fd, | ||
Latch * | latch, | ||
void * | user_data | ||
) |
Definition at line 862 of file latch.c.
References Assert, elog, ERROR, WaitEventSet::events, fd(), WaitEventSet::latch, MyProcPid, Latch::owner_pid, PGINVALID_SOCKET, postmaster_alive_fds, POSTMASTER_FD_WATCH, WaitEvent::user_data, WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_MASK.
Referenced by InitializeLatchWaitSet(), PgstatCollectorMain(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().
WaitEventSet* CreateWaitEventSet | ( | MemoryContext | context, |
int | nevents | ||
) |
Definition at line 684 of file latch.c.
References AcquireExternalFD(), close, elog, ERROR, MAXALIGN, MemoryContextAllocZero(), WaitEventSet::nevents, pgwin32_signal_event, ReleaseExternalFD(), and StaticAssertStmt.
Referenced by InitializeLatchWaitSet(), PgstatCollectorMain(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().
void DisownLatch | ( | Latch * | latch | ) |
Definition at line 424 of file latch.c.
References Assert, Latch::is_shared, MyProcPid, and Latch::owner_pid.
Referenced by AuxiliaryProcKill(), ProcKill(), and StartupXLOG().
void FreeWaitEventSet | ( | WaitEventSet * | set | ) |
Definition at line 798 of file latch.c.
References close, WaitEvent::events, WaitEvent::fd, pfree(), WaitEvent::pos, ReleaseExternalFD(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.
Referenced by PgstatCollectorMain(), ShutdownLatchSupport(), and WaitLatchOrSocket().
void InitializeLatchSupport | ( | void | ) |
Definition at line 192 of file latch.c.
References Assert, close, elog, FATAL, IsUnderPostmaster, MyProcPid, pqsignal(), ReleaseExternalFD(), ReserveExternalFD(), SIG_IGN, and UnBlockSig.
Referenced by InitPostmasterChild(), and InitStandaloneProcess().
void InitializeLatchWaitSet | ( | void | ) |
Definition at line 290 of file latch.c.
References AddWaitEventToSet(), Assert, CreateWaitEventSet(), IsUnderPostmaster, WaitEventSet::latch_pos, LatchWaitSetLatchPos, MyLatch, PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, TopMemoryContext, WL_EXIT_ON_PM_DEATH, and WL_LATCH_SET.
Referenced by InitPostmasterChild(), and InitStandaloneProcess().
void InitLatch | ( | Latch * | latch | ) |
Definition at line 338 of file latch.c.
References Assert, elog, ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, MyProcPid, and Latch::owner_pid.
Referenced by InitPostmasterChild(), and InitStandaloneProcess().
void InitSharedLatch | ( | Latch * | latch | ) |
Definition at line 371 of file latch.c.
References elog, ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, and Latch::owner_pid.
Referenced by InitProcGlobal(), and XLOGShmemInit().
void ModifyWaitEvent | ( | WaitEventSet * | set, |
int | pos, | ||
uint32 | events, | ||
Latch * | latch | ||
) |
Definition at line 948 of file latch.c.
References generate_unaccent_rules::action, Assert, elog, ereport, errcode_for_socket_access(), errmsg(), ERROR, WaitEventSet::events, WaitEvent::events, WaitEvent::fd, WaitEventSet::latch, MyProcPid, WaitEventSet::nevents, Latch::owner_pid, PGINVALID_SOCKET, PostmasterIsAlive, PostmasterPid, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_CONNECTED, WL_SOCKET_READABLE, and WL_SOCKET_WRITEABLE.
Referenced by secure_read(), secure_write(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), WaitLatch(), and WalSndWait().
void OwnLatch | ( | Latch * | latch | ) |
Definition at line 404 of file latch.c.
References Assert, elog, ERROR, Latch::is_shared, MyProcPid, and Latch::owner_pid.
Referenced by InitAuxiliaryProcess(), InitProcess(), and StartupXLOG().
void ResetLatch | ( | Latch * | latch | ) |
Definition at line 660 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(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), ConditionVariableTimedSleep(), copy_read_data(), gather_readnext(), initialize_worker_spi(), libpqrcv_connect(), libpqrcv_PQgetResult(), logicalrep_worker_stop(), LogicalRepApplyLoop(), mq_putmessage(), pg_promote(), pg_sleep(), pgarch_MainLoop(), pgfdw_get_cleanup_result(), pgfdw_get_result(), PgstatCollectorMain(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), secure_read(), secure_write(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), SyncRepWaitForLSN(), SysLoggerMain(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), WalReceiverMain(), WalSndLoop(), WalSndWaitForWal(), WalSndWriteData(), and WalWriterMain().
void SetLatch | ( | Latch * | latch | ) |
Definition at line 567 of file latch.c.
References Latch::is_set, kill, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, pg_memory_barrier, and waiting.
Referenced by avl_sigusr2_handler(), CheckDeadLockAlert(), ConditionVariableBroadcast(), ConditionVariableSignal(), die(), ForwardSyncRequest(), handle_sig_alarm(), HandleCatchupInterrupt(), HandleNotifyInterrupt(), HandleParallelMessageInterrupt(), IdleInTransactionSessionTimeoutHandler(), IdleSessionTimeoutHandler(), logicalrep_worker_wakeup_ptr(), pgarch_waken(), pgarch_waken_stop(), ProcessClientReadInterrupt(), ProcessClientWriteInterrupt(), ProcSendSignal(), procsignal_sigusr1_handler(), ProcWakeup(), RecoveryConflictInterrupt(), 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(), WakeupRecovery(), WalRcvForceReply(), WalSndLastCycleHandler(), WalSndWaitForWal(), WalSndWakeup(), WalSndWriteData(), write_syslogger_file(), and XLogSetAsyncXactLSN().
void ShutdownLatchSupport | ( | void | ) |
Definition at line 308 of file latch.c.
References close, FreeWaitEventSet(), InvalidPid, pqsignal(), and SIG_IGN.
Referenced by StartBackgroundWorker().
int WaitEventSetWait | ( | WaitEventSet * | set, |
long | timeout, | ||
WaitEvent * | occurred_events, | ||
int | nevents, | ||
uint32 | wait_event_info | ||
) |
Definition at line 1308 of file latch.c.
References Assert, buf, EAGAIN, EINTR, elog, ereport, errcode_for_socket_access(), errmsg(), ERROR, WaitEvent::events, EWOULDBLOCK, fd(), WaitEvent::fd, INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, WaitEventSet::nevents, pg_memory_barrier, PGINVALID_SOCKET, pgstat_report_wait_end(), pgstat_report_wait_start(), pgwin32_dispatch_queued_signals(), WaitEvent::pos, PostmasterIsAliveInternal(), proc_exit(), read, SIGNAL_ARGS, start_time, unlikely, WaitEvent::user_data, WaitEventSetWaitBlock(), waiting, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_CONNECTED, WL_SOCKET_MASK, WL_SOCKET_READABLE, WL_SOCKET_WRITEABLE, and write.
Referenced by PgstatCollectorMain(), secure_read(), secure_write(), SysLoggerMain(), WaitLatch(), WaitLatchOrSocket(), and WalSndWait().
|
inlinestatic |
Referenced by WaitEventSetWait().
Definition at line 452 of file latch.c.
References Assert, WaitEventSet::exit_on_postmaster_death, IsUnderPostmaster, LatchWaitSetLatchPos, ModifyWaitEvent(), WaitEventSetWait(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.
Referenced by ApplyLauncherMain(), autoprewarm_main(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), ConditionVariableTimedSleep(), gather_readnext(), initialize_worker_spi(), logicalrep_worker_stop(), mq_putmessage(), pg_promote(), pg_sleep(), pgarch_MainLoop(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), SyncRepWaitForLSN(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), and WalWriterMain().
int WaitLatchOrSocket | ( | Latch * | latch, |
int | wakeEvents, | ||
pgsocket | sock, | ||
long | timeout, | ||
uint32 | wait_event_info | ||
) |
Definition at line 500 of file latch.c.
References AddWaitEventToSet(), Assert, CreateWaitEventSet(), CurrentMemoryContext, 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(), LogicalRepApplyLoop(), pgfdw_get_cleanup_result(), pgfdw_get_result(), read_or_wait(), secure_open_gssapi(), and WalReceiverMain().
|
static |
|
static |
Definition at line 147 of file latch.c.
Referenced by run_permutation(), SetLatch(), try_complete_step(), and WaitEventSetWait().