timeout.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "datatype/timestamp.h"
  17. /*
  18. * Identifiers for timeout reasons. Note that in case multiple timeouts
  19. * trigger at the same time, they are serviced in the order of this enum.
  20. */
  21. typedef enum TimeoutId
  22. {
  23. /* Predefined timeout reasons */
  24. STARTUP_PACKET_TIMEOUT,
  25. DEADLOCK_TIMEOUT,
  26. LOCK_TIMEOUT,
  27. STATEMENT_TIMEOUT,
  28. STANDBY_DEADLOCK_TIMEOUT,
  29. STANDBY_TIMEOUT,
  30. STANDBY_LOCK_TIMEOUT,
  31. IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
  32. IDLE_SESSION_TIMEOUT,
  33. IDLE_STATS_UPDATE_TIMEOUT,
  34. CLIENT_CONNECTION_CHECK_TIMEOUT,
  35. STARTUP_PROGRESS_TIMEOUT,
  36. /* First user-definable timeout reason */
  37. USER_TIMEOUT,
  38. /* Maximum number of timeout reasons */
  39. MAX_TIMEOUTS = USER_TIMEOUT + 10
  40. } TimeoutId;
  41. /* callback function signature */
  42. typedef void (*timeout_handler_proc) (void);
  43. /*
  44. * Parameter structure for setting multiple timeouts at once
  45. */
  46. typedef enum TimeoutType
  47. {
  48. TMPARAM_AFTER,
  49. TMPARAM_AT,
  50. TMPARAM_EVERY
  51. } TimeoutType;
  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/EVERY */
  57. TimestampTz fin_time; /* only used for TMPARAM_AT */
  58. } EnableTimeoutParams;
  59. /*
  60. * Parameter structure for clearing multiple timeouts at once
  61. */
  62. typedef struct
  63. {
  64. TimeoutId id; /* timeout to clear */
  65. bool keep_indicator; /* keep the indicator flag? */
  66. } DisableTimeoutParams;
  67. /* timeout setup */
  68. extern void InitializeTimeouts(void);
  69. extern TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler);
  70. extern void reschedule_timeouts(void);
  71. /* timeout operation */
  72. extern void enable_timeout_after(TimeoutId id, int delay_ms);
  73. extern void enable_timeout_every(TimeoutId id, TimestampTz fin_time,
  74. int delay_ms);
  75. extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);
  76. extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);
  77. extern void disable_timeout(TimeoutId id, bool keep_indicator);
  78. extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);
  79. extern void disable_all_timeouts(bool keep_indicators);
  80. /* accessors */
  81. extern bool get_timeout_active(TimeoutId id);
  82. extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);
  83. extern TimestampTz get_timeout_start_time(TimeoutId id);
  84. extern TimestampTz get_timeout_finish_time(TimeoutId id);
  85. #endif /* TIMEOUT_H */