From 1364c80e6475525c2485e550a519cc2771ec7211 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 9 Jun 2024 14:59:34 +0200 Subject: [PATCH] mac/compat: add withLock fallback for xcode older than 14 withLock is available for macOS versions starting from 10.10 but can only be used on xcode 14+. xcode 14 introduced swift 5.7, so we guard it behind a swift version check. --- osdep/mac/swift_compat.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/osdep/mac/swift_compat.swift b/osdep/mac/swift_compat.swift index 6924d5cfca..54fadee3e2 100644 --- a/osdep/mac/swift_compat.swift +++ b/osdep/mac/swift_compat.swift @@ -15,6 +15,16 @@ * License along with mpv. If not, see . */ +#if !swift(>=5.7) +extension NSCondition { + func withLock(_ body: () throws -> R) rethrows -> R { + self.lock() + defer { self.unlock() } + return try body() + } +} +#endif + #if !swift(>=5.0) extension Data { mutating func withUnsafeMutableBytes(_ body: (UnsafeMutableRawBufferPointer) throws -> Type) rethrows -> Type {