Skip to content

Commit

Permalink
Only call SymInitialize once on Windows
Browse files Browse the repository at this point in the history
Looks like this can be an expensive operation [1] so we shouldn't be calling
it... once per symbol and stack trace!

[1]: rust-lang/rustup#591
  • Loading branch information
alexcrichton committed Jul 19, 2016
1 parent c677c4e commit 3cfb76a
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,15 @@ mod lock {
}
}

// requires external synchronization
#[cfg(all(windows, feature = "dbghelp"))]
fn dbghelp_init() -> Box<std::any::Any> {
use winapi::*;
struct Cleanup { handle: HANDLE }

impl Drop for Cleanup {
fn drop(&mut self) {
unsafe { ::dbghelp::SymCleanup(self.handle); }
}
}

unsafe {
let ret = ::dbghelp::SymInitializeW(kernel32::GetCurrentProcess(),
0 as *mut _, TRUE);
if ret != TRUE {
Box::new(())
} else {
Box::new(Cleanup { handle: kernel32::GetCurrentProcess() })
}
unsafe fn dbghelp_init() {
static mut INITIALIZED: bool = false;

if !INITIALIZED {
dbghelp::SymInitializeW(kernel32::GetCurrentProcess(),
0 as *mut _,
winapi::TRUE);
INITIALIZED = true;
}
}

0 comments on commit 3cfb76a

Please sign in to comment.