From 73a56c3d93ba1e1fe4ea538eedbfefb8ee93e2fa Mon Sep 17 00:00:00 2001 From: Peter Tang Date: Tue, 19 Sep 2023 09:21:07 +0800 Subject: [PATCH] consolidate to use threadSafeQueue only. --- Sources/SwiftMath/MathBundle/MathFont.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftMath/MathBundle/MathFont.swift b/Sources/SwiftMath/MathBundle/MathFont.swift index 4bfd2b4..81fc7c1 100644 --- a/Sources/SwiftMath/MathBundle/MathFont.swift +++ b/Sources/SwiftMath/MathBundle/MathFont.swift @@ -77,7 +77,6 @@ private class BundleManager { private var rawMathTables = [MathFont: NSDictionary]() private let threadSafeQueue = DispatchQueue(label: "com.smartmath.mathfont.threadsafequeue", attributes: .concurrent) - private let resourceLoadingQueue = DispatchQueue(label: "com.smartmath.mathfont.resourceLoader") private func registerCGFont(mathFont: MathFont) throws { guard let frameworkBundleURL = Bundle.module.url(forResource: "mathFonts", withExtension: "bundle"), @@ -126,7 +125,7 @@ private class BundleManager { private func onDemandRegistration(mathFont: MathFont) { guard threadSafeQueue.sync(execute: { cgFonts[mathFont] }) == nil else { return } // Note: resourceLoading is now serialized. - resourceLoadingQueue.sync { [weak self] in + threadSafeQueue.sync(flags: .barrier, execute: { [weak self] in if self?.cgFonts[mathFont] == nil { do { try BundleManager.manager.registerCGFont(mathFont: mathFont) @@ -136,7 +135,7 @@ private class BundleManager { fatalError("MTMathFonts:\(#function) ondemand loading failed, mathFont \(mathFont.rawValue), reason \(error)") } } - } + }) } fileprivate func obtainCGFont(font: MathFont) -> CGFont { onDemandRegistration(mathFont: font)