aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/dumputils.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-04-03 08:38:24 -0400
committerRobert Haas <rhaas@postgresql.org>2012-04-03 08:39:03 -0400
commit5e86c61a7eec0fdc6961493a150159fa8fc63b1c (patch)
tree5fae211af084d9d67bb9f75cfafd49c2ecde0539 /src/bin/pg_dump/dumputils.c
parent38b9693fd9847f4dcf6ff2fc469a7f2aac6385d9 (diff)
downloadpostgresql-5e86c61a7eec0fdc6961493a150159fa8fc63b1c.tar.gz
postgresql-5e86c61a7eec0fdc6961493a150159fa8fc63b1c.zip
Arrange for on_exit_nicely to be thread-safe.
Extracted from Joachim Wieland's parallel pg_dump patch, with some additional comments by me.
Diffstat (limited to 'src/bin/pg_dump/dumputils.c')
-rw-r--r--src/bin/pg_dump/dumputils.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index 9b306295150..c1a35b2ce80 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -1319,16 +1319,18 @@ on_exit_nicely(on_exit_nicely_callback function, void *arg)
on_exit_nicely_index++;
}
-/* Run accumulated on_exit_nicely callbacks and then exit quietly. */
+/*
+ * Run accumulated on_exit_nicely callbacks in reverse order and then exit
+ * quietly. This needs to be thread-safe.
+ */
void
exit_nicely(int code)
{
- while (--on_exit_nicely_index >= 0)
- (*on_exit_nicely_list[on_exit_nicely_index].function)(code,
- on_exit_nicely_list[on_exit_nicely_index].arg);
-#ifdef WIN32
- if (parallel_init_done && GetCurrentThreadId() != mainThreadId)
- ExitThread(code);
-#endif
+ int i;
+
+ for (i = on_exit_nicely_index - 1; i >= 0; i--)
+ (*on_exit_nicely_list[i].function)(code,
+ on_exit_nicely_list[i].arg);
+
exit(code);
}