|
37 | 37 | *
|
38 | 38 | *
|
39 | 39 | * 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 $ |
41 | 41 | *
|
42 | 42 | * NOTES
|
43 | 43 | *
|
@@ -2016,6 +2016,36 @@ reaper(SIGNAL_ARGS)
|
2016 | 2016 | errno=save_errno;
|
2017 | 2017 | }
|
2018 | 2018 |
|
| 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 | + |
2019 | 2049 | /*
|
2020 | 2050 | * CleanupProc -- cleanup after terminated backend.
|
2021 | 2051 | *
|
@@ -2069,7 +2099,11 @@ CleanupProc(int pid,
|
2069 | 2099 | elseif (pid==BgWriterPID)
|
2070 | 2100 | BgWriterPID=0;
|
2071 | 2101 | else
|
| 2102 | +#ifndefWIN32 |
2072 | 2103 | pgstat_beterm(pid);
|
| 2104 | +#else |
| 2105 | +win32_pgstat_beterm(pid); |
| 2106 | +#endif |
2073 | 2107 |
|
2074 | 2108 | return;
|
2075 | 2109 | }
|
|