]> granicus.if.org Git - postgresql/commitdiff
Here is a patch that implements setitimer() on win32. With this patch
authorBruce Momjian <bruce@momjian.us>
Wed, 18 Feb 2004 16:25:12 +0000 (16:25 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 18 Feb 2004 16:25:12 +0000 (16:25 +0000)
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

src/backend/libpq/pqsignal.c
src/backend/port/win32/Makefile
src/backend/port/win32/timer.c [new file with mode: 0644]
src/backend/storage/lmgr/proc.c
src/include/port/win32.h

index 7c4e67ffcce3893b69741587be01faaf054104ba..34e5883797e905c95dd0c638181daf316cc0c4e5 100644 (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 ||
index 647370ebcdc62a915820dfae9a65bf496c1bfde3..16f6c75bc42df389d55b3e201240182f95890d43 100644 (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
 
diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c
new file mode 100644 (file)
index 0000000..8202efe
--- /dev/null
@@ -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;
+}
index f6d7c634a718feb12e283ec614a85f4f6d3d837e..19ce44ff687f46e47adeece77b60763c7fa4db45 100644 (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
        }
 
index 9a98c72dc18148621ea389b3ea75660fc34c2945..22c36a7320f40212e5cf6c5159a18f34a31e317f 100644 (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 */
 
 /*