mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
81f477e4a7
Reorganise the thread locals for the backtracing code in the `Runtime` module so that there’s only one set of them, with everything else hanging off that. This also reduces code duplication and consumption of thread local variable space. Fix the `DefaultSymbolLocator`’s shared instance to be thread local. rdar://171432566
49 lines
1.5 KiB
Swift
49 lines
1.5 KiB
Swift
//===--- PeImageCache.swift - PE-COFF support for Swift -------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Provides a per-thread PE-COFF image cache that improves efficiency when
|
|
// taking multiple backtraces by avoiding loading PE-COFF images multiple times.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Swift
|
|
|
|
/// Provides a per-thread image cache for PE-COFF image processing. This means
|
|
/// if you take multiple backtraces from a thread, you won't load the same
|
|
/// image multiple times.
|
|
final class PeImageCache {
|
|
var cache: [String: PeCoffImage] = [:]
|
|
|
|
func purge() {
|
|
cache = [:]
|
|
}
|
|
|
|
func lookup(path: String?) -> PeCoffImage? {
|
|
guard let path = path else {
|
|
return nil
|
|
}
|
|
if let image = cache[path] {
|
|
return image
|
|
}
|
|
if let source = try? ImageSource(path: path),
|
|
let image = try? PeCoffImage(source: source) {
|
|
cache[path] = image
|
|
return image
|
|
}
|
|
return nil
|
|
}
|
|
|
|
static var threadLocal: PeImageCache {
|
|
return BacktracerThreadLocals.threadLocal.peImageCache
|
|
}
|
|
}
|