]> granicus.if.org Git - postgresql/commitdiff
Arrange for on_exit_nicely to be thread-safe.
authorRobert Haas <rhaas@postgresql.org>
Tue, 3 Apr 2012 12:38:24 +0000 (08:38 -0400)
committerRobert Haas <rhaas@postgresql.org>
Tue, 3 Apr 2012 12:39:03 +0000 (08:39 -0400)
Extracted from Joachim Wieland's parallel pg_dump patch, with some
additional comments by me.

src/bin/pg_dump/dumputils.c

index 9b30629515083f2af2b25a088d00aa448ab5711a..c1a35b2ce806017d2f344e1061fc85a5b2986d2e 100644 (file)
@@ -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);
 }