Header And Logo

PostgreSQL
| The world's most advanced open source database.

timeout.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * timeout.h
00004  *    Routines to multiplex SIGALRM interrupts for multiple timeout reasons.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/utils/timeout.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef TIMEOUT_H
00015 #define TIMEOUT_H
00016 
00017 #include "datatype/timestamp.h"
00018 
00019 /*
00020  * Identifiers for timeout reasons.  Note that in case multiple timeouts
00021  * trigger at the same time, they are serviced in the order of this enum.
00022  */
00023 typedef enum TimeoutId
00024 {
00025     /* Predefined timeout reasons */
00026     STARTUP_PACKET_TIMEOUT,
00027     DEADLOCK_TIMEOUT,
00028     LOCK_TIMEOUT,
00029     STATEMENT_TIMEOUT,
00030     STANDBY_DEADLOCK_TIMEOUT,
00031     STANDBY_TIMEOUT,
00032     /* First user-definable timeout reason */
00033     USER_TIMEOUT,
00034     /* Maximum number of timeout reasons */
00035     MAX_TIMEOUTS = 16
00036 } TimeoutId;
00037 
00038 /* callback function signature */
00039 typedef void (*timeout_handler_proc) (void);
00040 
00041 /*
00042  * Parameter structure for setting multiple timeouts at once
00043  */
00044 typedef enum TimeoutType
00045 {
00046     TMPARAM_AFTER,
00047     TMPARAM_AT
00048 } TimeoutType;
00049 
00050 typedef struct
00051 {
00052     TimeoutId   id;             /* timeout to set */
00053     TimeoutType type;           /* TMPARAM_AFTER or TMPARAM_AT */
00054     int         delay_ms;       /* only used for TMPARAM_AFTER */
00055     TimestampTz fin_time;       /* only used for TMPARAM_AT */
00056 } EnableTimeoutParams;
00057 
00058 /*
00059  * Parameter structure for clearing multiple timeouts at once
00060  */
00061 typedef struct
00062 {
00063     TimeoutId   id;             /* timeout to clear */
00064     bool        keep_indicator; /* keep the indicator flag? */
00065 } DisableTimeoutParams;
00066 
00067 /* timeout setup */
00068 extern void InitializeTimeouts(void);
00069 extern TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler);
00070 
00071 /* timeout operation */
00072 extern void enable_timeout_after(TimeoutId id, int delay_ms);
00073 extern void enable_timeout_at(TimeoutId id, TimestampTz fin_time);
00074 extern void enable_timeouts(const EnableTimeoutParams *timeouts, int count);
00075 extern void disable_timeout(TimeoutId id, bool keep_indicator);
00076 extern void disable_timeouts(const DisableTimeoutParams *timeouts, int count);
00077 extern void disable_all_timeouts(bool keep_indicators);
00078 
00079 /* accessors */
00080 extern bool get_timeout_indicator(TimeoutId id, bool reset_indicator);
00081 extern TimestampTz get_timeout_start_time(TimeoutId id);
00082 
00083 #endif   /* TIMEOUT_H */