Commit 5e86c61a authored by Robert Haas's avatar Robert Haas

Arrange for on_exit_nicely to be thread-safe.

Extracted from Joachim Wieland's parallel pg_dump patch, with some
additional comments by me.
parent 38b9693f
...@@ -1319,16 +1319,18 @@ on_exit_nicely(on_exit_nicely_callback function, void *arg) ...@@ -1319,16 +1319,18 @@ on_exit_nicely(on_exit_nicely_callback function, void *arg)
on_exit_nicely_index++; 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 void
exit_nicely(int code) exit_nicely(int code)
{ {
while (--on_exit_nicely_index >= 0) int i;
(*on_exit_nicely_list[on_exit_nicely_index].function)(code,
on_exit_nicely_list[on_exit_nicely_index].arg); for (i = on_exit_nicely_index - 1; i >= 0; i--)
#ifdef WIN32 (*on_exit_nicely_list[i].function)(code,
if (parallel_init_done && GetCurrentThreadId() != mainThreadId) on_exit_nicely_list[i].arg);
ExitThread(code);
#endif
exit(code); exit(code);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment