From ed86b48cc9a8349e8e99de5f013f68f1edff4121 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 25 Nov 2013 18:27:27 -0800 Subject: Clean up statically initialized data on shutdown Whenever the runtime is shut down, add a few hooks to clean up some of the statically initialized data of the runtime. Note that this is an unsafe operation because there's no guarantee on behalf of the runtime that there's no other code running which is using the runtime. This helps turn down the noise a bit in the valgrind output related to statically initialized mutexes. It doesn't turn the noise down to 0 because there are still statically initialized mutexes in dynamic_lib and os::with_env_lock, but I believe that it would be easy enough to add exceptions for those cases and I don't think that it's the runtime's job to go and clean up that data. --- src/libstd/rt/args.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/libstd/rt/args.rs') diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 43e8096a8b1..7b27161ab5d 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -32,8 +32,8 @@ pub unsafe fn init(argc: int, argv: **u8) { imp::init(argc, argv) } pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } /// One-time global cleanup. -#[cfg(not(test))] pub fn cleanup() { imp::cleanup() } -#[cfg(test)] pub fn cleanup() { realargs::cleanup() } +#[cfg(not(test))] pub unsafe fn cleanup() { imp::cleanup() } +#[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() } /// Take the global arguments from global storage. #[cfg(not(test))] pub fn take() -> Option<~[~str]> { imp::take() } @@ -74,14 +74,16 @@ mod imp { use vec; static mut global_args_ptr: uint = 0; + static mut lock: Mutex = MUTEX_INIT; pub unsafe fn init(argc: int, argv: **u8) { let args = load_argc_and_argv(argc, argv); put(args); } - pub fn cleanup() { + pub unsafe fn cleanup() { rtassert!(take().is_some()); + lock.destroy(); } pub fn take() -> Option<~[~str]> { @@ -108,7 +110,6 @@ mod imp { } fn with_lock(f: || -> T) -> T { - static mut lock: Mutex = MUTEX_INIT; (|| { unsafe { lock.lock(); -- cgit 1.4.1-3-g733a5