aboutsummaryrefslogtreecommitdiff
path: root/src/uv-common.c
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2020-04-22 12:24:34 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2020-04-22 12:24:36 +0200
commit72fe3543feb23ae555e08628b70a3fae4da5706c (patch)
treede8a3f9515a42dc1c8bfd92d9b62a4b6bf6c9b4e /src/uv-common.c
parentb29612fe59f664d9b370dceda1060b1dc1deaff0 (diff)
downloadlibuv-72fe3543feb23ae555e08628b70a3fae4da5706c.tar.gz
libuv-72fe3543feb23ae555e08628b70a3fae4da5706c.zip
unix,win: add uv_library_shutdown()
Make it possible to explicitly tell libuv to release any resources it's still holding onto (memory, threads, file descriptors, etc.) Before this commit, cleanup was performed in various destructors. This commit centralizes the cleanup logic, enabling the addition of `uv_library_shutdown()`, but maintains the current observable behavior of cleaning up when libuv is unloaded by means of `dlclose(3)`. Fixes: https://github.com/libuv/libuv/issues/2763 PR-URL: https://github.com/libuv/libuv/pull/2764 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Diffstat (limited to 'src/uv-common.c')
-rw-r--r--src/uv-common.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/uv-common.c b/src/uv-common.c
index 5cb1a8c8..f69a2c1d 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -821,3 +821,19 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
uv__free(cpu_infos);
}
+
+
+#ifdef __GNUC__ /* Also covers __clang__ and __INTEL_COMPILER. */
+__attribute__((destructor))
+#endif
+void uv_library_shutdown(void) {
+ static int was_shutdown;
+
+ if (was_shutdown)
+ return;
+
+ uv__process_title_cleanup();
+ uv__signal_cleanup();
+ uv__threadpool_cleanup();
+ was_shutdown = 1;
+}