1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Here is a patch that implements setitimer() on win32. With this patch

applied, deadlock detection and statement_timeout now works.

The file timer.c goes into src/backend/port/win32/.

The patch also removes two lines of "printf debugging" accidentally left
in pqsignal.h, in the console control handler.

Magnus Hagander
This commit is contained in:
Bruce Momjian
2004-02-18 16:25:12 +00:00
parent f8257734e4
commit af3b182a57
5 changed files with 79 additions and 20 deletions

View File

@@ -0,0 +1,65 @@
/*-------------------------------------------------------------------------
*
* timer.c
* Microsoft Windows Win32 Timer Implementation
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/port/win32/timer.c,v 1.1 2004/02/18 16:25:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "libpq/pqsignal.h"
static HANDLE timerHandle = INVALID_HANDLE_VALUE;
static VOID CALLBACK timer_completion(LPVOID arg, DWORD timeLow, DWORD timeHigh) {
pg_queue_signal(SIGALRM);
}
/*
* Limitations of this implementation:
*
* - Does not support setting ovalue
* - Does not support interval timer (value->it_interval)
* - Only supports ITIMER_REAL
*/
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) {
LARGE_INTEGER dueTime;
Assert(ovalue == NULL);
Assert(value != NULL);
Assert(value->it_interval.tv_sec == 0 && value->it_interval.tv_usec == 0);
Assert(which == ITIMER_REAL);
if (timerHandle == INVALID_HANDLE_VALUE) {
/* First call in this backend, create new timer object */
timerHandle = CreateWaitableTimer(NULL, TRUE, NULL);
if (timerHandle == NULL)
ereport(FATAL,
(errmsg_internal("failed to create waitable timer: %i",GetLastError())));
}
if (value->it_value.tv_sec == 0 &&
value->it_value.tv_usec == 0) {
/* Turn timer off */
CancelWaitableTimer(timerHandle);
return 0;
}
/* Negative time to SetWaitableTimer means relative time */
dueTime.QuadPart = -(value->it_value.tv_usec*10 + value->it_value.tv_sec*10000000L);
/* Turn timer on, or change timer */
if (!SetWaitableTimer(timerHandle, &dueTime, 0, timer_completion, NULL, FALSE))
ereport(FATAL,
(errmsg_internal("failed to set waitable timer: %i",GetLastError())));
return 0;
}