aboutsummaryrefslogtreecommitdiff
path: root/src/backend/port/win32/timer.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2004-02-18 16:25:12 +0000
committerBruce Momjian <bruce@momjian.us>2004-02-18 16:25:12 +0000
commitaf3b182a574e4b349dcf71279769ad18818b13b9 (patch)
tree4867fe86fc8d2866669b03c1f761fd02bb845f65 /src/backend/port/win32/timer.c
parentf8257734e4add3204f4d6d38f3edea0c827b245f (diff)
downloadpostgresql-af3b182a574e4b349dcf71279769ad18818b13b9.tar.gz
postgresql-af3b182a574e4b349dcf71279769ad18818b13b9.zip
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
Diffstat (limited to 'src/backend/port/win32/timer.c')
-rw-r--r--src/backend/port/win32/timer.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c
new file mode 100644
index 00000000000..8202efe3c4b
--- /dev/null
+++ b/src/backend/port/win32/timer.c
@@ -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;
+}