Skip to content

Commit 3cfb76a

Browse files
committed
Only call SymInitialize once on Windows
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
1 parent c677c4e commit 3cfb76a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/lib.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,15 @@ mod lock {
145145
}
146146
}
147147

148+
// requires external synchronization
148149
#[cfg(all(windows, feature = "dbghelp"))]
149-
fn dbghelp_init() -> Box<std::any::Any> {
150-
use winapi::*;
151-
struct Cleanup { handle: HANDLE }
152-
153-
impl Drop for Cleanup {
154-
fn drop(&mut self) {
155-
unsafe { ::dbghelp::SymCleanup(self.handle); }
156-
}
157-
}
158-
159-
unsafe {
160-
let ret = ::dbghelp::SymInitializeW(kernel32::GetCurrentProcess(),
161-
0 as *mut _, TRUE);
162-
if ret != TRUE {
163-
Box::new(())
164-
} else {
165-
Box::new(Cleanup { handle: kernel32::GetCurrentProcess() })
166-
}
150+
unsafe fn dbghelp_init() {
151+
static mut INITIALIZED: bool = false;
152+
153+
if !INITIALIZED {
154+
dbghelp::SymInitializeW(kernel32::GetCurrentProcess(),
155+
0 as *mut _,
156+
winapi::TRUE);
157+
INITIALIZED = true;
167158
}
168159
}

0 commit comments

Comments
 (0)