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-2021, 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 */
37  /* First user-definable timeout reason */
39  /* Maximum number of timeout reasons */
42 
43 /* callback function signature */
44 typedef void (*timeout_handler_proc) (void);
45 
46 /*
47  * Parameter structure for setting multiple timeouts at once
48  */
49 typedef enum TimeoutType
50 {
55 
56 typedef struct
57 {
58  TimeoutId id; /* timeout to set */
59  TimeoutType type; /* TMPARAM_AFTER or TMPARAM_AT */
60  int delay_ms; /* only used for TMPARAM_AFTER/EVERY */
61  TimestampTz fin_time; /* only used for TMPARAM_AT */
63 
64 /*
65  * Parameter structure for clearing multiple timeouts at once
66  */
67 typedef struct
68 {
69  TimeoutId id; /* timeout to clear */
70  bool keep_indicator; /* keep the indicator flag? */
72 
73 /* timeout setup */
74 extern void InitializeTimeouts(void);
76 extern void reschedule_timeouts(void);
77 
78 /* timeout operation */
79 extern void enable_timeout_after(TimeoutId id, int delay_ms);
80 extern void enable_timeout_every(TimeoutId id, TimestampTz fin_time,
81  int delay_ms);
82 extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);
83 extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);
84 extern void disable_timeout(TimeoutId id, bool keep_indicator);
85 extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);
86 extern void disable_all_timeouts(bool keep_indicators);
87 
88 /* accessors */
89 extern bool get_timeout_active(TimeoutId id);
90 extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);
93 
94 #endif /* TIMEOUT_H */
int64 TimestampTz
Definition: timestamp.h:39
TimeoutId id
Definition: timeout.h:69
TimeoutType type
Definition: timeout.h:59
TimestampTz fin_time
Definition: timeout.h:61
TimeoutId id
Definition: timeout.h:58
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition: timeout.c:551
void reschedule_timeouts(void)
Definition: timeout.c:531
bool get_timeout_active(TimeoutId id)
Definition: timeout.c:771
void(* timeout_handler_proc)(void)
Definition: timeout.h:44
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:742
TimestampTz get_timeout_finish_time(TimeoutId id)
Definition: timeout.c:818
void InitializeTimeouts(void)
Definition: timeout.c:461
TimestampTz get_timeout_start_time(TimeoutId id)
Definition: timeout.c:804
void enable_timeout_every(TimeoutId id, TimestampTz fin_time, int delay_ms)
Definition: timeout.c:575
TimeoutId
Definition: timeout.h:24
@ STARTUP_PROGRESS_TIMEOUT
Definition: timeout.h:36
@ 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:40
@ USER_TIMEOUT
Definition: timeout.h:38
@ CLIENT_CONNECTION_CHECK_TIMEOUT
Definition: timeout.h:35
@ STANDBY_TIMEOUT
Definition: timeout.h:31
void enable_timeout_at(TimeoutId id, TimestampTz fin_time)
Definition: timeout.c:598
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:676
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition: timeout.c:621
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:496
TimeoutType
Definition: timeout.h:50
@ TMPARAM_AT
Definition: timeout.h:52
@ TMPARAM_EVERY
Definition: timeout.h:53
@ TMPARAM_AFTER
Definition: timeout.h:51
void disable_timeouts(const DisableTimeoutParams *timeouts, int count)
Definition: timeout.c:709
bool get_timeout_indicator(TimeoutId id, bool reset_indicator)
Definition: timeout.c:784