 
 import Foundation
 
-// MARK: - ImageDecoderRegistry
-
 /// A registry of image codecs.
-public final class ImageDecoderRegistry {
+public final class ImageDecoderRegistry: @unchecked Sendable {
     /// A shared registry.
     public static let shared = ImageDecoderRegistry()
 
     private var matches = [(ImageDecodingContext) -> ImageDecoding?]()
+    private let lock = NSLock()
 
     /// Initializes a custom registry.
     init() {


    /// Returns a decoder that matches the given context.
    public func decoder(for context: ImageDecodingContext) -> ImageDecoding? {
        for match in matches.reversed() {
            if let decoder = match(context) {
                return decoder

    /// including progressively decoded images. If the decoder doesn't support
    /// progressive decoding, return `nil` when `isCompleted` is `false`.
    public func register(_ match: @escaping (ImageDecodingContext) -> ImageDecoding?) {
        lock.lock()
        defer { lock.unlock() }

        matches.append(match)
    }

    /// Removes all registered decoders.
    public func clear() {
        lock.lock()
        defer { lock.unlock() }

        matches = []
    }
}

/// Image decoding context used when selecting which decoder to use.
public struct ImageDecodingContext: @unchecked Sendable {
    public var request: ImageRequest
    public var data: Data
    /// Returns `true` if the download was completed.
