codekingpro/portable-devtools
116k
1/*-------------------------------------------------------------------------2 *3 * timeout.h4 * Routines to multiplex SIGALRM interrupts for multiple timeout reasons.5 *6 *7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group8 * Portions Copyright (c) 1994, Regents of the University of California9 *10 * src/include/utils/timeout.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef TIMEOUT_H15#define TIMEOUT_H16 17#include "datatype/timestamp.h"18 19/*20 * Identifiers for timeout reasons. Note that in case multiple timeouts21 * trigger at the same time, they are serviced in the order of this enum.22 */23typedef enum TimeoutId24{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 IDLE_SESSION_TIMEOUT,35 IDLE_STATS_UPDATE_TIMEOUT,36 CLIENT_CONNECTION_CHECK_TIMEOUT,37 STARTUP_PROGRESS_TIMEOUT,38 /* First user-definable timeout reason */39 USER_TIMEOUT,40 /* Maximum number of timeout reasons */41 MAX_TIMEOUTS = USER_TIMEOUT + 1042} TimeoutId;43 44/* callback function signature */45typedef void (*timeout_handler_proc) (void);46 47/*48 * Parameter structure for setting multiple timeouts at once49 */50typedef enum TimeoutType51{52 TMPARAM_AFTER,53 TMPARAM_AT,54 TMPARAM_EVERY55} TimeoutType;56 57typedef struct58{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 */63} EnableTimeoutParams;64 65/*66 * Parameter structure for clearing multiple timeouts at once67 */68typedef struct69{70 TimeoutId id; /* timeout to clear */71 bool keep_indicator; /* keep the indicator flag? */72} DisableTimeoutParams;73 74/* timeout setup */75extern void InitializeTimeouts(void);76extern TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler);77extern void reschedule_timeouts(void);78 79/* timeout operation */80extern void enable_timeout_after(TimeoutId id, int delay_ms);81extern void enable_timeout_every(TimeoutId id, TimestampTz fin_time,82 int delay_ms);83extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);84extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);85extern void disable_timeout(TimeoutId id, bool keep_indicator);86extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);87extern void disable_all_timeouts(bool keep_indicators);88 89/* accessors */90extern bool get_timeout_active(TimeoutId id);91extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);92extern TimestampTz get_timeout_start_time(TimeoutId id);93extern TimestampTz get_timeout_finish_time(TimeoutId id);94 95#endif /* TIMEOUT_H */96 