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

Commit51b4885

Browse files
committed
Here's a patch implementing the "thread method" to workaround the bug
with socket calls in signal handlers (APC) on Win32. See details in mailto pgsql-hackers-win32 a couple of minutes ago.Magnus Hagander
1 parentb8fd675 commit51b4885

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.376 2004/03/23 01:23:48 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.377 2004/03/24 04:04:51 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -2016,6 +2016,36 @@ reaper(SIGNAL_ARGS)
20162016
errno=save_errno;
20172017
}
20182018

2019+
2020+
#ifdefWIN32
2021+
/*
2022+
* On WIN32, we cannot use socket functions inside
2023+
* an APC (signal handler). If we do, select() will return
2024+
* with incorrect return values, causing the postmaster to
2025+
* enter a blocking accept(). We work around this by
2026+
* running it on a separate thread. We still block the main
2027+
* thread until it is done, so we don't scribble over any
2028+
* data from the wrong thread (pgstat functions aqre not
2029+
* thread safe).
2030+
*/
2031+
staticDWORDWINAPIwin32_pgstat_beterm_thread(LPVOIDparam)
2032+
{
2033+
pgstat_beterm((int)param);
2034+
return0;
2035+
}
2036+
2037+
staticvoidwin32_pgstat_beterm(intpid) {
2038+
HANDLEbeterm_thread=CreateThread(NULL,64*1024,win32_pgstat_beterm_thread, (LPVOID)pid,0,NULL);
2039+
if (!beterm_thread)
2040+
ereport(FATAL,
2041+
(errmsg_internal("failed to create beterm sender thread: %i", (int)GetLastError())));
2042+
if (WaitForSingleObject(beterm_thread,INFINITE)!=WAIT_OBJECT_0)
2043+
ereport(FATAL,
2044+
(errmsg_internal("failed to wait for beterm sender thread: %i", (int)GetLastError())));
2045+
CloseHandle(beterm_thread);
2046+
}
2047+
#endif
2048+
20192049
/*
20202050
* CleanupProc -- cleanup after terminated backend.
20212051
*
@@ -2069,7 +2099,11 @@ CleanupProc(int pid,
20692099
elseif (pid==BgWriterPID)
20702100
BgWriterPID=0;
20712101
else
2102+
#ifndefWIN32
20722103
pgstat_beterm(pid);
2104+
#else
2105+
win32_pgstat_beterm(pid);
2106+
#endif
20732107

20742108
return;
20752109
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp