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

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.31 2004/02/08 22:28:56 neilc Exp $
* $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.32 2004/02/18 16:25:12 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@ -429,8 +429,6 @@ pg_signal_thread(LPVOID param)
/* Console control handler will execute on a thread created
by the OS at the time of invocation */
static BOOL WINAPI pg_console_handler(DWORD dwCtrlType) {
printf("Console handler being called!\n");
fflush(stdout);
if (dwCtrlType == CTRL_C_EVENT ||
dwCtrlType == CTRL_BREAK_EVENT ||
dwCtrlType == CTRL_CLOSE_EVENT ||

View File

@ -4,7 +4,7 @@
# Makefile for port/win32
#
# IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.2 2003/11/29 19:51:54 pgsql Exp $
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.3 2004/02/18 16:25:12 momjian Exp $
#
#-------------------------------------------------------------------------
@ -12,7 +12,7 @@ subdir = src/backend/port/win32
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
OBJS = sema.o shmem.o
OBJS = sema.o shmem.o timer.o
all: SUBSYS.o

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;
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.146 2004/02/08 22:28:56 neilc Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.147 2004/02/18 16:25:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -972,9 +972,6 @@ ProcSendSignal(BackendId procId)
bool
enable_sig_alarm(int delayms, bool is_statement_timeout)
{
#ifdef WIN32
#warning add Win32 timer
#else
struct timeval fin_time;
#ifndef __BEOS__
@ -1044,7 +1041,6 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
time_interval = delayms * 1000; /* usecs */
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
return false;
#endif
#endif
return true;
}
@ -1059,10 +1055,6 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
bool
disable_sig_alarm(bool is_statement_timeout)
{
#ifdef WIN32
#warning add Win32 timer
#else
/*
* Always disable the interrupt if it is active; this avoids being
* interrupted by the signal handler and thereby possibly getting
@ -1102,7 +1094,6 @@ disable_sig_alarm(bool is_statement_timeout)
if (!CheckStatementTimeout())
return false;
}
#endif
return true;
}
@ -1135,9 +1126,6 @@ CheckStatementTimeout(void)
else
{
/* Not time yet, so (re)schedule the interrupt */
#ifdef WIN32
#warning add win32 timer
#else
#ifndef __BEOS__
struct itimerval timeval;
@ -1160,7 +1148,6 @@ CheckStatementTimeout(void)
(statement_fin_time.tv_usec - now.tv_usec);
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
return false;
#endif
#endif
}

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.17 2004/02/08 22:28:57 neilc Exp $ */
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.18 2004/02/18 16:25:12 momjian Exp $ */
/* undefine and redefine after #include */
#undef mkdir
@ -132,6 +132,15 @@ struct timezone
int tz_dsttime; /* Nonzero if DST is ever in effect. */
};
/* for setitimer in backend/port/win32/timer.c */
#define ITIMER_REAL 0
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
/* FROM SRA */
/*