64 #define disable_alarm() (alarm_enabled = false)
65 #define enable_alarm() (alarm_enabled = true)
88 if (active_timeouts[i]->
index ==
id)
105 elog(
FATAL,
"timeout index %d out of range 0..%d", index,
106 num_active_timeouts);
108 for (i = num_active_timeouts - 1; i >= index; i--)
109 active_timeouts[i + 1] = active_timeouts[i];
111 active_timeouts[index] = &all_timeouts[id];
113 num_active_timeouts++;
125 elog(
FATAL,
"timeout index %d out of range 0..%d", index,
129 active_timeouts[i - 1] = active_timeouts[i];
131 num_active_timeouts--;
144 Assert(all_timeouts[
id].timeout_handler !=
NULL);
162 if (fin_time < old_timeout->fin_time)
164 if (fin_time == old_timeout->
fin_time && id < old_timeout->
index)
173 all_timeouts[id].
fin_time = fin_time;
203 if (secs == 0 && usecs == 0)
243 elog(
FATAL,
"could not enable SIGALRM timer: %m");
261 int save_errno = errno;
294 now >= active_timeouts[0]->fin_time)
383 if (all_timeouts[
id].timeout_handler ==
NULL)
385 if (
id >= MAX_TIMEOUTS)
387 (
errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
388 errmsg(
"cannot add more timeout reasons")));
391 Assert(all_timeouts[
id].timeout_handler ==
NULL);
487 for (i = 0; i < count; i++)
492 switch (timeouts[i].type)
496 timeouts[i].delay_ms);
505 elog(
ERROR,
"unrecognized timeout type %d",
506 (
int) timeouts[i].type);
531 Assert(all_timeouts[
id].timeout_handler !=
NULL);
571 for (i = 0; i < count; i++)
576 Assert(all_timeouts[
id].timeout_handler !=
NULL);
582 if (!timeouts[i].keep_indicator)
611 elog(
FATAL,
"could not disable SIGALRM timer: %m");
616 if (!keep_indicators)
621 all_timeouts[i].indicator =
false;
635 if (all_timeouts[
id].indicator)
static bool all_timeouts_initialized
TimestampTz get_timeout_start_time(TimeoutId id)
void InitializeTimeouts(void)
static void remove_timeout_index(int index)
TimestampTz GetCurrentTimestamp(void)
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
Datum idx(PG_FUNCTION_ARGS)
timeout_handler_proc timeout_handler
void disable_timeouts(const DisableTimeoutParams *timeouts, int count)
void reschedule_timeouts(void)
#define RESUME_INTERRUPTS()
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
void enable_timeout_at(TimeoutId id, TimestampTz fin_time)
void disable_all_timeouts(bool keep_indicators)
static timeout_params all_timeouts[MAX_TIMEOUTS]
static void enable_timeout(TimeoutId id, TimestampTz now, TimestampTz fin_time)
static void insert_timeout(TimeoutId id, int index)
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
#define ereport(elevel, rest)
static volatile sig_atomic_t alarm_enabled
static void schedule_alarm(TimestampTz now)
bool get_timeout_indicator(TimeoutId id, bool reset_indicator)
#define TimestampTzPlusMilliseconds(tz, ms)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
void enable_timeout_after(TimeoutId id, int delay_ms)
void SetLatch(volatile Latch *latch)
#define Assert(condition)
static timeout_params *volatile active_timeouts[MAX_TIMEOUTS]
static int find_active_timeout(TimeoutId id)
int errmsg(const char *fmt,...)
#define HOLD_INTERRUPTS()
struct timeout_params timeout_params
void disable_timeout(TimeoutId id, bool keep_indicator)
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
static volatile int num_active_timeouts
Datum now(PG_FUNCTION_ARGS)
void(* timeout_handler_proc)(void)
static void handle_sig_alarm(SIGNAL_ARGS)