PostgreSQL Source Code git master
timeout.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * timeout.h
4 * Routines to multiplex SIGALRM interrupts for multiple timeout reasons.
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/utils/timeout.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef TIMEOUT_H
15#define TIMEOUT_H
16
17#include "datatype/timestamp.h"
18
19/*
20 * Identifiers for timeout reasons. Note that in case multiple timeouts
21 * trigger at the same time, they are serviced in the order of this enum.
22 */
23typedef enum TimeoutId
24{
25 /* Predefined timeout reasons */
39 /* First user-definable timeout reason */
41 /* Maximum number of timeout reasons */
44
45/* callback function signature */
46typedef void (*timeout_handler_proc) (void);
47
48/*
49 * Parameter structure for setting multiple timeouts at once
50 */
51typedef enum TimeoutType
52{
57
58typedef struct
59{
60 TimeoutId id; /* timeout to set */
61 TimeoutType type; /* TMPARAM_AFTER or TMPARAM_AT */
62 int delay_ms; /* only used for TMPARAM_AFTER/EVERY */
63 TimestampTz fin_time; /* only used for TMPARAM_AT */
65
66/*
67 * Parameter structure for clearing multiple timeouts at once
68 */
69typedef struct
70{
71 TimeoutId id; /* timeout to clear */
72 bool keep_indicator; /* keep the indicator flag? */
74
75/* timeout setup */
76extern void InitializeTimeouts(void);
78extern void reschedule_timeouts(void);
79
80/* timeout operation */
81extern void enable_timeout_after(TimeoutId id, int delay_ms);
82extern void enable_timeout_every(TimeoutId id, TimestampTz fin_time,
83 int delay_ms);
84extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);
85extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);
86extern void disable_timeout(TimeoutId id, bool keep_indicator);
87extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);
88extern void disable_all_timeouts(bool keep_indicators);
89
90/* accessors */
91extern bool get_timeout_active(TimeoutId id);
92extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);
95
96#endif /* TIMEOUT_H */
int64 TimestampTz
Definition: timestamp.h:39
TimeoutId id
Definition: timeout.h:71
TimeoutType type
Definition: timeout.h:61
TimestampTz fin_time
Definition: timeout.h:63
TimeoutId id
Definition: timeout.h:60
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition: timeout.c:560
void reschedule_timeouts(void)
Definition: timeout.c:540
bool get_timeout_active(TimeoutId id)
Definition: timeout.c:780
void(* timeout_handler_proc)(void)
Definition: timeout.h:46
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:751
TimestampTz get_timeout_finish_time(TimeoutId id)
Definition: timeout.c:827
void InitializeTimeouts(void)
Definition: timeout.c:470
TimestampTz get_timeout_start_time(TimeoutId id)
Definition: timeout.c:813
void enable_timeout_every(TimeoutId id, TimestampTz fin_time, int delay_ms)
Definition: timeout.c:584
TimeoutId
Definition: timeout.h:24
@ STARTUP_PROGRESS_TIMEOUT
Definition: timeout.h:38
@ STANDBY_LOCK_TIMEOUT
Definition: timeout.h:32
@ IDLE_SESSION_TIMEOUT
Definition: timeout.h:35
@ STARTUP_PACKET_TIMEOUT
Definition: timeout.h:26
@ IDLE_IN_TRANSACTION_SESSION_TIMEOUT
Definition: timeout.h:33
@ LOCK_TIMEOUT
Definition: timeout.h:28
@ STANDBY_DEADLOCK_TIMEOUT
Definition: timeout.h:30
@ STATEMENT_TIMEOUT
Definition: timeout.h:29
@ DEADLOCK_TIMEOUT
Definition: timeout.h:27
@ MAX_TIMEOUTS
Definition: timeout.h:42
@ TRANSACTION_TIMEOUT
Definition: timeout.h:34
@ USER_TIMEOUT
Definition: timeout.h:40
@ IDLE_STATS_UPDATE_TIMEOUT
Definition: timeout.h:36
@ CLIENT_CONNECTION_CHECK_TIMEOUT
Definition: timeout.h:37
@ STANDBY_TIMEOUT
Definition: timeout.h:31
void enable_timeout_at(TimeoutId id, TimestampTz fin_time)
Definition: timeout.c:607
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:685
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition: timeout.c:630
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:505
TimeoutType
Definition: timeout.h:52
@ TMPARAM_AT
Definition: timeout.h:54
@ TMPARAM_EVERY
Definition: timeout.h:55
@ TMPARAM_AFTER
Definition: timeout.h:53
void disable_timeouts(const DisableTimeoutParams *timeouts, int count)
Definition: timeout.c:718
bool get_timeout_indicator(TimeoutId id, bool reset_indicator)
Definition: timeout.c:793