Extracted from Joachim Wieland's parallel pg_dump patch, with some
additional comments by me.
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);
}