Skip to content

Commit af3b182

Browse files
committed
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
1 parent f825773 commit af3b182

File tree

5 files changed

+79
-20
lines changed

5 files changed

+79
-20
lines changed

src/backend/libpq/pqsignal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.31 2004/02/08 22:28:56 neilc Exp $
12+
* $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.32 2004/02/18 16:25:12 momjian Exp $
1313
*
1414
* NOTES
1515
* This shouldn't be in libpq, but the monitor and some other
@@ -429,8 +429,6 @@ pg_signal_thread(LPVOID param)
429429
/* Console control handler will execute on a thread created
430430
by the OS at the time of invocation */
431431
static BOOL WINAPI pg_console_handler(DWORD dwCtrlType) {
432-
printf("Console handler being called!\n");
433-
fflush(stdout);
434432
if (dwCtrlType == CTRL_C_EVENT ||
435433
dwCtrlType == CTRL_BREAK_EVENT ||
436434
dwCtrlType == CTRL_CLOSE_EVENT ||

src/backend/port/win32/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for port/win32
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.2 2003/11/29 19:51:54 pgsql Exp $
7+
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.3 2004/02/18 16:25:12 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/port/win32
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = sema.o shmem.o
15+
OBJS = sema.o shmem.o timer.o
1616

1717
all: SUBSYS.o
1818

src/backend/port/win32/timer.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* timer.c
4+
* Microsoft Windows Win32 Timer Implementation
5+
*
6+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7+
*
8+
* IDENTIFICATION
9+
* $PostgreSQL: pgsql/src/backend/port/win32/timer.c,v 1.1 2004/02/18 16:25:12 momjian Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "postgres.h"
15+
16+
#include "libpq/pqsignal.h"
17+
18+
19+
static HANDLE timerHandle = INVALID_HANDLE_VALUE;
20+
21+
static VOID CALLBACK timer_completion(LPVOID arg, DWORD timeLow, DWORD timeHigh) {
22+
pg_queue_signal(SIGALRM);
23+
}
24+
25+
26+
/*
27+
* Limitations of this implementation:
28+
*
29+
* - Does not support setting ovalue
30+
* - Does not support interval timer (value->it_interval)
31+
* - Only supports ITIMER_REAL
32+
*/
33+
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) {
34+
LARGE_INTEGER dueTime;
35+
36+
Assert(ovalue == NULL);
37+
Assert(value != NULL);
38+
Assert(value->it_interval.tv_sec == 0 && value->it_interval.tv_usec == 0);
39+
Assert(which == ITIMER_REAL);
40+
41+
if (timerHandle == INVALID_HANDLE_VALUE) {
42+
/* First call in this backend, create new timer object */
43+
timerHandle = CreateWaitableTimer(NULL, TRUE, NULL);
44+
if (timerHandle == NULL)
45+
ereport(FATAL,
46+
(errmsg_internal("failed to create waitable timer: %i",GetLastError())));
47+
}
48+
49+
if (value->it_value.tv_sec == 0 &&
50+
value->it_value.tv_usec == 0) {
51+
/* Turn timer off */
52+
CancelWaitableTimer(timerHandle);
53+
return 0;
54+
}
55+
56+
/* Negative time to SetWaitableTimer means relative time */
57+
dueTime.QuadPart = -(value->it_value.tv_usec*10 + value->it_value.tv_sec*10000000L);
58+
59+
/* Turn timer on, or change timer */
60+
if (!SetWaitableTimer(timerHandle, &dueTime, 0, timer_completion, NULL, FALSE))
61+
ereport(FATAL,
62+
(errmsg_internal("failed to set waitable timer: %i",GetLastError())));
63+
64+
return 0;
65+
}

src/backend/storage/lmgr/proc.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.146 2004/02/08 22:28:56 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.147 2004/02/18 16:25:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -972,9 +972,6 @@ ProcSendSignal(BackendId procId)
972972
bool
973973
enable_sig_alarm(int delayms, bool is_statement_timeout)
974974
{
975-
#ifdef WIN32
976-
#warning add Win32 timer
977-
#else
978975
struct timeval fin_time;
979976

980977
#ifndef __BEOS__
@@ -1044,7 +1041,6 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
10441041
time_interval = delayms * 1000; /* usecs */
10451042
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
10461043
return false;
1047-
#endif
10481044
#endif
10491045
return true;
10501046
}
@@ -1059,10 +1055,6 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
10591055
bool
10601056
disable_sig_alarm(bool is_statement_timeout)
10611057
{
1062-
#ifdef WIN32
1063-
#warning add Win32 timer
1064-
#else
1065-
10661058
/*
10671059
* Always disable the interrupt if it is active; this avoids being
10681060
* interrupted by the signal handler and thereby possibly getting
@@ -1102,7 +1094,6 @@ disable_sig_alarm(bool is_statement_timeout)
11021094
if (!CheckStatementTimeout())
11031095
return false;
11041096
}
1105-
#endif
11061097
return true;
11071098
}
11081099

@@ -1135,9 +1126,6 @@ CheckStatementTimeout(void)
11351126
else
11361127
{
11371128
/* Not time yet, so (re)schedule the interrupt */
1138-
#ifdef WIN32
1139-
#warning add win32 timer
1140-
#else
11411129
#ifndef __BEOS__
11421130
struct itimerval timeval;
11431131

@@ -1160,7 +1148,6 @@ CheckStatementTimeout(void)
11601148
(statement_fin_time.tv_usec - now.tv_usec);
11611149
if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
11621150
return false;
1163-
#endif
11641151
#endif
11651152
}
11661153

src/include/port/win32.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.17 2004/02/08 22:28:57 neilc Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.18 2004/02/18 16:25:12 momjian Exp $ */
22

33
/* undefine and redefine after #include */
44
#undef mkdir
@@ -132,6 +132,15 @@ struct timezone
132132
int tz_dsttime; /* Nonzero if DST is ever in effect. */
133133
};
134134

135+
/* for setitimer in backend/port/win32/timer.c */
136+
#define ITIMER_REAL 0
137+
struct itimerval {
138+
struct timeval it_interval;
139+
struct timeval it_value;
140+
};
141+
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
142+
143+
135144
/* FROM SRA */
136145

137146
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy