1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * timeout.h |
4 | * Routines to multiplex SIGALRM interrupts for multiple timeout reasons. |
5 | * |
6 | * |
7 | * Portions Copyright (c) 1996-2019, 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 */ |
26 | STARTUP_PACKET_TIMEOUT, |
27 | DEADLOCK_TIMEOUT, |
28 | LOCK_TIMEOUT, |
29 | STATEMENT_TIMEOUT, |
30 | STANDBY_DEADLOCK_TIMEOUT, |
31 | STANDBY_TIMEOUT, |
32 | STANDBY_LOCK_TIMEOUT, |
33 | IDLE_IN_TRANSACTION_SESSION_TIMEOUT, |
34 | /* First user-definable timeout reason */ |
35 | USER_TIMEOUT, |
36 | /* Maximum number of timeout reasons */ |
37 | MAX_TIMEOUTS = 16 |
38 | } TimeoutId; |
39 | |
40 | /* callback function signature */ |
41 | typedef void (*timeout_handler_proc) (void); |
42 | |
43 | /* |
44 | * Parameter structure for setting multiple timeouts at once |
45 | */ |
46 | typedef enum TimeoutType |
47 | { |
48 | TMPARAM_AFTER, |
49 | TMPARAM_AT |
50 | } TimeoutType; |
51 | |
52 | typedef struct |
53 | { |
54 | TimeoutId id; /* timeout to set */ |
55 | TimeoutType type; /* TMPARAM_AFTER or TMPARAM_AT */ |
56 | int delay_ms; /* only used for TMPARAM_AFTER */ |
57 | TimestampTz fin_time; /* only used for TMPARAM_AT */ |
58 | } EnableTimeoutParams; |
59 | |
60 | /* |
61 | * Parameter structure for clearing multiple timeouts at once |
62 | */ |
63 | typedef struct |
64 | { |
65 | TimeoutId id; /* timeout to clear */ |
66 | bool keep_indicator; /* keep the indicator flag? */ |
67 | } DisableTimeoutParams; |
68 | |
69 | /* timeout setup */ |
70 | extern void InitializeTimeouts(void); |
71 | extern TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler); |
72 | extern void reschedule_timeouts(void); |
73 | |
74 | /* timeout operation */ |
75 | extern void enable_timeout_after(TimeoutId id, int delay_ms); |
76 | extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time); |
77 | extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count); |
78 | extern void disable_timeout(TimeoutId id, bool keep_indicator); |
79 | extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count); |
80 | extern void disable_all_timeouts(bool keep_indicators); |
81 | |
82 | /* accessors */ |
83 | extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator); |
84 | extern TimestampTz get_timeout_start_time(TimeoutId id); |
85 | extern TimestampTz get_timeout_finish_time(TimeoutId id); |
86 | |
87 | #endif /* TIMEOUT_H */ |
88 | |