Skip to content

Commit 5e86c61

Browse files
committed
Arrange for on_exit_nicely to be thread-safe.
Extracted from Joachim Wieland's parallel pg_dump patch, with some additional comments by me.
1 parent 38b9693 commit 5e86c61

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/bin/pg_dump/dumputils.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,16 +1319,18 @@ on_exit_nicely(on_exit_nicely_callback function, void *arg)
13191319
on_exit_nicely_index++;
13201320
}
13211321

1322-
/* Run accumulated on_exit_nicely callbacks and then exit quietly. */
1322+
/*
1323+
* Run accumulated on_exit_nicely callbacks in reverse order and then exit
1324+
* quietly. This needs to be thread-safe.
1325+
*/
13231326
void
13241327
exit_nicely(int code)
13251328
{
1326-
while (--on_exit_nicely_index >= 0)
1327-
(*on_exit_nicely_list[on_exit_nicely_index].function)(code,
1328-
on_exit_nicely_list[on_exit_nicely_index].arg);
1329-
#ifdef WIN32
1330-
if (parallel_init_done && GetCurrentThreadId() != mainThreadId)
1331-
ExitThread(code);
1332-
#endif
1329+
int i;
1330+
1331+
for (i = on_exit_nicely_index - 1; i >= 0; i--)
1332+
(*on_exit_nicely_list[i].function)(code,
1333+
on_exit_nicely_list[i].arg);
1334+
13331335
exit(code);
13341336
}

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