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
*
*
* 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
/* 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 ||
# 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 $
#
#-------------------------------------------------------------------------
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
-OBJS = sema.o shmem.o
+OBJS = sema.o shmem.o timer.o
all: SUBSYS.o
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * 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;
+}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
bool
enable_sig_alarm(int delayms, bool is_statement_timeout)
{
-#ifdef WIN32
-#warning add Win32 timer
-#else
struct timeval fin_time;
#ifndef __BEOS__
time_interval = delayms * 1000; /* usecs */
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
return false;
-#endif
#endif
return true;
}
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
if (!CheckStatementTimeout())
return false;
}
-#endif
return true;
}
else
{
/* Not time yet, so (re)schedule the interrupt */
-#ifdef WIN32
-#warning add win32 timer
-#else
#ifndef __BEOS__
struct itimerval timeval;
(statement_fin_time.tv_usec - now.tv_usec);
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
return false;
-#endif
#endif
}
-/* $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
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 */
/*