threadsafe protect CTFontCreateWithGraphicsFont

This commit is contained in:
Peter Tang
2023-09-18 21:54:45 +08:00
parent 045c2aab72
commit 024468cddd

View File

@@ -156,11 +156,15 @@ private class BundleManager {
} }
//Note: ctfont creation and caching is now threadsafe. //Note: ctfont creation and caching is now threadsafe.
guard threadSafeQueue.sync(execute: { ctFonts[fontSizePair] }) == nil else { return ctFonts[fontSizePair]! } guard threadSafeQueue.sync(execute: { ctFonts[fontSizePair] }) == nil else { return ctFonts[fontSizePair]! }
let newCTFont = CTFontCreateWithGraphicsFont(cgFont, size, nil, nil) return threadSafeQueue.sync(flags: .barrier, execute: {
threadSafeQueue.sync(flags: .barrier) { if let ctfont = ctFonts[fontSizePair] {
ctFonts[fontSizePair] = newCTFont return ctfont
} else {
let result = CTFontCreateWithGraphicsFont(cgFont, size, nil, nil)
ctFonts[fontSizePair] = result
return result
} }
return newCTFont })
} }
fileprivate func obtainRawMathTable(font: MathFont) -> NSDictionary { fileprivate func obtainRawMathTable(font: MathFont) -> NSDictionary {
onDemandRegistration(mathFont: font) onDemandRegistration(mathFont: font)