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-2022, 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  */
23 typedef enum TimeoutId
24 {
25  /* Predefined timeout reasons */
38  /* First user-definable timeout reason */
40  /* Maximum number of timeout reasons */
43 
44 /* callback function signature */
45 typedef void (*timeout_handler_proc) (void);
46 
47 /*
48  * Parameter structure for setting multiple timeouts at once
49  */
50 typedef enum TimeoutType
51 {
56 
57 typedef struct
58 {
59  TimeoutId id; /* timeout to set */
60  TimeoutType type; /* TMPARAM_AFTER or TMPARAM_AT */
61  int delay_ms; /* only used for TMPARAM_AFTER/EVERY */
62  TimestampTz fin_time; /* only used for TMPARAM_AT */
64 
65 /*
66  * Parameter structure for clearing multiple timeouts at once
67  */
68 typedef struct
69 {
70  TimeoutId id; /* timeout to clear */
71  bool keep_indicator; /* keep the indicator flag? */
73 
74 /* timeout setup */
75 extern void InitializeTimeouts(void);
77 extern void reschedule_timeouts(void);
78 
79 /* timeout operation */
80 extern void enable_timeout_after(TimeoutId id, int delay_ms);
81 extern void enable_timeout_every(TimeoutId id, TimestampTz fin_time,
82  int delay_ms);
83 extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);
84 extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);
85 extern void disable_timeout(TimeoutId id, bool keep_indicator);
86 extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);
87 extern void disable_all_timeouts(bool keep_indicators);
88 
89 /* accessors */
90 extern bool get_timeout_active(TimeoutId id);
91 extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);
94 
95 #endif /* TIMEOUT_H */
int64 TimestampTz
Definition: timestamp.h:39
TimeoutId id
Definition: timeout.h:70
TimeoutType type
Definition: timeout.h:60
TimestampTz fin_time
Definition: timeout.h:62
TimeoutId id
Definition: timeout.h:59
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition: timeout.c:564
void reschedule_timeouts(void)
Definition: timeout.c:544
bool get_timeout_active(TimeoutId id)
Definition: timeout.c:784
void(* timeout_handler_proc)(void)
Definition: timeout.h:45
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:755
TimestampTz get_timeout_finish_time(TimeoutId id)
Definition: timeout.c:831
void InitializeTimeouts(void)
Definition: timeout.c:474
TimestampTz get_timeout_start_time(TimeoutId id)
Definition: timeout.c:817
void enable_timeout_every(TimeoutId id, TimestampTz fin_time, int delay_ms)
Definition: timeout.c:588
TimeoutId
Definition: timeout.h:24
@ STARTUP_PROGRESS_TIMEOUT
Definition: timeout.h:37
@ STANDBY_LOCK_TIMEOUT
Definition: timeout.h:32
@ IDLE_SESSION_TIMEOUT
Definition: timeout.h:34
@ 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:41
@ USER_TIMEOUT
Definition: timeout.h:39
@ IDLE_STATS_UPDATE_TIMEOUT
Definition: timeout.h:35
@ CLIENT_CONNECTION_CHECK_TIMEOUT
Definition: timeout.h:36
@ STANDBY_TIMEOUT
Definition: timeout.h:31
void enable_timeout_at(TimeoutId id, TimestampTz fin_time)
Definition: timeout.c:611
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:689
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition: timeout.c:634
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:509
TimeoutType
Definition: timeout.h:51
@ TMPARAM_AT
Definition: timeout.h:53
@ TMPARAM_EVERY
Definition: timeout.h:54
@ TMPARAM_AFTER
Definition: timeout.h:52
void disable_timeouts(const DisableTimeoutParams *timeouts, int count)
Definition: timeout.c:722
bool get_timeout_indicator(TimeoutId id, bool reset_indicator)
Definition: timeout.c:797