Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf3b182

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 leftin pqsignal.h, in the console control handler.Magnus Hagander
1 parentf825773 commitaf3b182

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
staticBOOLWINAPIpg_console_handler(DWORDdwCtrlType) {
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+
staticHANDLEtimerHandle=INVALID_HANDLE_VALUE;
20+
21+
staticVOIDCALLBACKtimer_completion(LPVOIDarg,DWORDtimeLow,DWORDtimeHigh) {
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+
intsetitimer(intwhich,conststructitimerval*value,structitimerval*ovalue) {
34+
LARGE_INTEGERdueTime;
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+
return0;
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+
return0;
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(intdelayms,boolis_statement_timeout)
974974
{
975-
#ifdefWIN32
976-
#warning add Win32 timer
977-
#else
978975
structtimevalfin_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(boolis_statement_timeout)
10611057
{
1062-
#ifdefWIN32
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-
#ifdefWIN32
1139-
#warning add win32 timer
1140-
#else
11411129
#ifndef__BEOS__
11421130
structitimervaltimeval;
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
inttz_dsttime;/* Nonzero if DST is ever in effect. */
133133
};
134134

135+
/* for setitimer in backend/port/win32/timer.c */
136+
#defineITIMER_REAL 0
137+
structitimerval {
138+
structtimevalit_interval;
139+
structtimevalit_value;
140+
};
141+
intsetitimer(intwhich,conststructitimerval*value,structitimerval*ovalue);
142+
143+
135144
/* FROM SRA */
136145

137146
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp