@@ -15,7 +15,6 @@ use core::convert::TryFrom;
15
15
use core:: mem;
16
16
use core:: u32;
17
17
use findshlibs:: { self , Segment , SharedLibrary } ;
18
- use lazy_static:: lazy_static;
19
18
use libc:: c_void;
20
19
use memmap:: Mmap ;
21
20
use std:: env;
@@ -330,23 +329,26 @@ impl Mapping {
330
329
}
331
330
}
332
331
333
- lazy_static ! {
334
- // A very small, very simple LRU cache for debug info mappings.
335
- //
336
- // The hit rate should be very high, since the typical stack doesn't cross
337
- // between many shared libraries.
338
- //
339
- // The `addr2line::Context` structures are pretty expensive to create. Its
340
- // cost is expected to be amortized by subsequent `locate` queries, which
341
- // leverage the structures built when constructing `addr2line::Context`s to
342
- // get nice speedups. If we didn't have this cache, that amortization would
343
- // never happen, and symbolicating backtraces would be ssssllllooooowwww.
344
- static ref MAPPINGS_CACHE : Mutex <Vec <( PathBuf , Mapping ) >>
345
- = Mutex :: new( Vec :: with_capacity( MAPPINGS_CACHE_SIZE ) ) ;
332
+ // A very small, very simple LRU cache for debug info mappings.
333
+ //
334
+ // The hit rate should be very high, since the typical stack doesn't cross
335
+ // between many shared libraries.
336
+ //
337
+ // The `addr2line::Context` structures are pretty expensive to create. Its
338
+ // cost is expected to be amortized by subsequent `locate` queries, which
339
+ // leverage the structures built when constructing `addr2line::Context`s to
340
+ // get nice speedups. If we didn't have this cache, that amortization would
341
+ // never happen, and symbolicating backtraces would be ssssllllooooowwww.
342
+ static mut MAPPINGS_CACHE : Option < Mutex < Vec < ( PathBuf , Mapping ) > > > = None ;
343
+
344
+ fn lazy_cache ( ) -> & ' static Mutex < Vec < ( PathBuf , Mapping ) > > {
345
+ unsafe {
346
+ MAPPINGS_CACHE . get_or_insert_with ( || Mutex :: new ( Vec :: with_capacity ( MAPPINGS_CACHE_SIZE ) ) )
347
+ }
346
348
}
347
349
348
350
pub fn clear_symbol_cache ( ) {
349
- if let Ok ( mut cache) = MAPPINGS_CACHE . lock ( ) {
351
+ if let Ok ( mut cache) = lazy_cache ( ) . lock ( ) {
350
352
cache. clear ( ) ;
351
353
}
352
354
}
@@ -355,8 +357,7 @@ fn with_mapping_for_path<F>(path: PathBuf, f: F)
355
357
where
356
358
F : FnMut ( & Context < ' _ > ) ,
357
359
{
358
- if let Ok ( mut cache) = MAPPINGS_CACHE . lock ( ) {
359
-
360
+ if let Ok ( mut cache) = lazy_cache ( ) . lock ( ) {
360
361
let idx = cache. iter ( ) . position ( |& ( ref p, _) | p == & path) ;
361
362
362
363
// Invariant: after this conditional completes without early returning
0 commit comments