Here's a patch implementing the "thread method" to workaround the bug
with socket calls in signal handlers (APC) on Win32. See details in mail to pgsql-hackers-win32 a couple of minutes ago. Magnus Hagander
This commit is contained in:
parent
b8fd6756e2
commit
51b488535e
@ -37,7 +37,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.376 2004/03/23 01:23:48 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.377 2004/03/24 04:04:51 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
@ -2016,6 +2016,36 @@ reaper_done:
|
|||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/*
|
||||||
|
* On WIN32, we cannot use socket functions inside
|
||||||
|
* an APC (signal handler). If we do, select() will return
|
||||||
|
* with incorrect return values, causing the postmaster to
|
||||||
|
* enter a blocking accept(). We work around this by
|
||||||
|
* running it on a separate thread. We still block the main
|
||||||
|
* thread until it is done, so we don't scribble over any
|
||||||
|
* data from the wrong thread (pgstat functions aqre not
|
||||||
|
* thread safe).
|
||||||
|
*/
|
||||||
|
static DWORD WINAPI win32_pgstat_beterm_thread(LPVOID param)
|
||||||
|
{
|
||||||
|
pgstat_beterm((int)param);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void win32_pgstat_beterm(int pid) {
|
||||||
|
HANDLE beterm_thread = CreateThread(NULL, 64*1024, win32_pgstat_beterm_thread, (LPVOID)pid, 0, NULL);
|
||||||
|
if (!beterm_thread)
|
||||||
|
ereport(FATAL,
|
||||||
|
(errmsg_internal("failed to create beterm sender thread: %i", (int)GetLastError())));
|
||||||
|
if (WaitForSingleObject(beterm_thread,INFINITE) != WAIT_OBJECT_0)
|
||||||
|
ereport(FATAL,
|
||||||
|
(errmsg_internal("failed to wait for beterm sender thread: %i", (int)GetLastError())));
|
||||||
|
CloseHandle(beterm_thread);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CleanupProc -- cleanup after terminated backend.
|
* CleanupProc -- cleanup after terminated backend.
|
||||||
*
|
*
|
||||||
@ -2069,7 +2099,11 @@ CleanupProc(int pid,
|
|||||||
else if (pid == BgWriterPID)
|
else if (pid == BgWriterPID)
|
||||||
BgWriterPID = 0;
|
BgWriterPID = 0;
|
||||||
else
|
else
|
||||||
|
#ifndef WIN32
|
||||||
pgstat_beterm(pid);
|
pgstat_beterm(pid);
|
||||||
|
#else
|
||||||
|
win32_pgstat_beterm(pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user