timeout.h 2.5 KB

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