#include "datatype/timestamp.h"

Go to the source code of this file.
| typedef void(* timeout_handler_proc)(void) |
| typedef enum TimeoutType TimeoutType |
| enum TimeoutId |
| STARTUP_PACKET_TIMEOUT | |
| DEADLOCK_TIMEOUT | |
| LOCK_TIMEOUT | |
| STATEMENT_TIMEOUT | |
| STANDBY_DEADLOCK_TIMEOUT | |
| STANDBY_TIMEOUT | |
| USER_TIMEOUT | |
| MAX_TIMEOUTS |
Definition at line 23 of file timeout.h.
{
/* Predefined timeout reasons */
STARTUP_PACKET_TIMEOUT,
DEADLOCK_TIMEOUT,
LOCK_TIMEOUT,
STATEMENT_TIMEOUT,
STANDBY_DEADLOCK_TIMEOUT,
STANDBY_TIMEOUT,
/* First user-definable timeout reason */
USER_TIMEOUT,
/* Maximum number of timeout reasons */
MAX_TIMEOUTS = 16
} TimeoutId;
| enum TimeoutType |
Definition at line 44 of file timeout.h.
{
TMPARAM_AFTER,
TMPARAM_AT
} TimeoutType;
| void disable_all_timeouts | ( | bool | keep_indicators | ) |
Definition at line 564 of file timeout.c.
References disable_alarm, elog, FATAL, i, ITIMER_REAL, MemSet, NULL, num_active_timeouts, and setitimer().
Referenced by AutoVacLauncherMain(), PostgresMain(), and ResolveRecoveryConflictWithBufferPin().
{
disable_alarm();
/*
* Only bother to reset the timer if we think it's active. We could just
* let the interrupt happen anyway, but it's probably a bit cheaper to do
* setitimer() than to let the useless interrupt happen.
*/
if (num_active_timeouts > 0)
{
struct itimerval timeval;
MemSet(&timeval, 0, sizeof(struct itimerval));
if (setitimer(ITIMER_REAL, &timeval, NULL) != 0)
elog(FATAL, "could not disable SIGALRM timer: %m");
}
num_active_timeouts = 0;
if (!keep_indicators)
{
int i;
for (i = 0; i < MAX_TIMEOUTS; i++)
all_timeouts[i].indicator = false;
}
}
Definition at line 493 of file timeout.c.
References all_timeouts_initialized, Assert, disable_alarm, find_active_timeout(), GetCurrentTimestamp(), i, timeout_params::indicator, NULL, num_active_timeouts, remove_timeout_index(), and schedule_alarm().
Referenced by BackendInitialize(), finish_xact_command(), PerformAuthentication(), ProcSleep(), StandbyTimeoutHandler(), and start_xact_command().
{
int i;
/* Assert request is sane */
Assert(all_timeouts_initialized);
Assert(all_timeouts[id].timeout_handler != NULL);
/* Disable timeout interrupts for safety. */
disable_alarm();
/* Find the timeout and remove it from the active list. */
i = find_active_timeout(id);
if (i >= 0)
remove_timeout_index(i);
/* Mark it inactive, whether it was active or not. */
if (!keep_indicator)
all_timeouts[id].indicator = false;
/* Reschedule the interrupt, if any timeouts remain active. */
if (num_active_timeouts > 0)
schedule_alarm(GetCurrentTimestamp());
}
| void disable_timeouts | ( | const DisableTimeoutParams * | timeouts, | |
| int | count | |||
| ) |
Definition at line 529 of file timeout.c.
References all_timeouts_initialized, Assert, disable_alarm, find_active_timeout(), GetCurrentTimestamp(), i, DisableTimeoutParams::id, timeout_params::indicator, NULL, num_active_timeouts, remove_timeout_index(), and schedule_alarm().
Referenced by LockErrorCleanup(), and ProcSleep().
{
int i;
Assert(all_timeouts_initialized);
/* Disable timeout interrupts for safety. */
disable_alarm();
/* Cancel the timeout(s). */
for (i = 0; i < count; i++)
{
TimeoutId id = timeouts[i].id;
int idx;
Assert(all_timeouts[id].timeout_handler != NULL);
idx = find_active_timeout(id);
if (idx >= 0)
remove_timeout_index(idx);
if (!timeouts[i].keep_indicator)
all_timeouts[id].indicator = false;
}
/* Reschedule the interrupt, if any timeouts remain active. */
if (num_active_timeouts > 0)
schedule_alarm(GetCurrentTimestamp());
}
| void enable_timeout_after | ( | TimeoutId | id, | |
| int | delay_ms | |||
| ) |
Definition at line 396 of file timeout.c.
References disable_alarm, enable_timeout(), GetCurrentTimestamp(), schedule_alarm(), and TimestampTzPlusMilliseconds.
Referenced by BackendInitialize(), PerformAuthentication(), ProcSleep(), ResolveRecoveryConflictWithBufferPin(), and start_xact_command().
{
TimestampTz now;
TimestampTz fin_time;
/* Disable timeout interrupts for safety. */
disable_alarm();
/* Queue the timeout at the appropriate time. */
now = GetCurrentTimestamp();
fin_time = TimestampTzPlusMilliseconds(now, delay_ms);
enable_timeout(id, now, fin_time);
/* Set the timer interrupt. */
schedule_alarm(now);
}
| void enable_timeout_at | ( | TimeoutId | id, | |
| TimestampTz | fin_time | |||
| ) |
Definition at line 421 of file timeout.c.
References disable_alarm, enable_timeout(), GetCurrentTimestamp(), and schedule_alarm().
{
TimestampTz now;
/* Disable timeout interrupts for safety. */
disable_alarm();
/* Queue the timeout at the appropriate time. */
now = GetCurrentTimestamp();
enable_timeout(id, now, fin_time);
/* Set the timer interrupt. */
schedule_alarm(now);
}
| void enable_timeouts | ( | const EnableTimeoutParams * | timeouts, | |
| int | count | |||
| ) |
Definition at line 444 of file timeout.c.
References disable_alarm, elog, enable_timeout(), ERROR, GetCurrentTimestamp(), i, EnableTimeoutParams::id, schedule_alarm(), TimestampTzPlusMilliseconds, TMPARAM_AFTER, and TMPARAM_AT.
Referenced by ProcSleep(), and ResolveRecoveryConflictWithBufferPin().
{
TimestampTz now;
int i;
/* Disable timeout interrupts for safety. */
disable_alarm();
/* Queue the timeout(s) at the appropriate times. */
now = GetCurrentTimestamp();
for (i = 0; i < count; i++)
{
TimeoutId id = timeouts[i].id;
TimestampTz fin_time;
switch (timeouts[i].type)
{
case TMPARAM_AFTER:
fin_time = TimestampTzPlusMilliseconds(now,
timeouts[i].delay_ms);
enable_timeout(id, now, fin_time);
break;
case TMPARAM_AT:
enable_timeout(id, now, timeouts[i].fin_time);
break;
default:
elog(ERROR, "unrecognized timeout type %d",
(int) timeouts[i].type);
break;
}
}
/* Set the timer interrupt. */
schedule_alarm(now);
}
Definition at line 601 of file timeout.c.
References timeout_params::indicator.
Referenced by ProcessInterrupts().
{
if (all_timeouts[id].indicator)
{
if (reset_indicator)
all_timeouts[id].indicator = false;
return true;
}
return false;
}
| TimestampTz get_timeout_start_time | ( | TimeoutId | id | ) |
Definition at line 621 of file timeout.c.
References timeout_params::start_time.
Referenced by ProcSleep().
{
return all_timeouts[id].start_time;
}
| void InitializeTimeouts | ( | void | ) |
Definition at line 332 of file timeout.c.
References all_timeouts_initialized, disable_alarm, timeout_params::fin_time, handle_sig_alarm(), i, timeout_params::index, timeout_params::indicator, num_active_timeouts, pqsignal(), SIGALRM, timeout_params::start_time, and timeout_params::timeout_handler.
Referenced by AutoVacLauncherMain(), AutoVacWorkerMain(), BackendInitialize(), do_start_bgworker(), PostgresMain(), StartupProcessMain(), and WalSndSignals().
{
int i;
/* Initialize, or re-initialize, all local state */
disable_alarm();
num_active_timeouts = 0;
for (i = 0; i < MAX_TIMEOUTS; i++)
{
all_timeouts[i].index = i;
all_timeouts[i].indicator = false;
all_timeouts[i].timeout_handler = NULL;
all_timeouts[i].start_time = 0;
all_timeouts[i].fin_time = 0;
}
all_timeouts_initialized = true;
/* Now establish the signal handler */
pqsignal(SIGALRM, handle_sig_alarm);
}
| TimeoutId RegisterTimeout | ( | TimeoutId | id, | |
| timeout_handler_proc | handler | |||
| ) |
Definition at line 365 of file timeout.c.
References all_timeouts_initialized, Assert, ereport, errcode(), errmsg(), FATAL, NULL, timeout_params::timeout_handler, and USER_TIMEOUT.
Referenced by BackendInitialize(), InitPostgres(), and StartupProcessMain().
{
Assert(all_timeouts_initialized);
/* There's no need to disable the signal handler here. */
if (id >= USER_TIMEOUT)
{
/* Allocate a user-defined timeout reason */
for (id = USER_TIMEOUT; id < MAX_TIMEOUTS; id++)
if (all_timeouts[id].timeout_handler == NULL)
break;
if (id >= MAX_TIMEOUTS)
ereport(FATAL,
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
errmsg("cannot add more timeout reasons")));
}
Assert(all_timeouts[id].timeout_handler == NULL);
all_timeouts[id].timeout_handler = handler;
return id;
}
1.7.1