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.
This commit is contained in:
der richter 2024-06-09 14:59:34 +02:00
parent b390ade709
commit 1364c80e64
1 changed files with 10 additions and 0 deletions

View File

@ -15,6 +15,16 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#if !swift(>=5.7)
extension NSCondition {
func withLock<R>(_ body: () throws -> R) rethrows -> R {
self.lock()
defer { self.unlock() }
return try body()
}
}
#endif
#if !swift(>=5.0)
extension Data {
mutating func withUnsafeMutableBytes<Type>(_ body: (UnsafeMutableRawBufferPointer) throws -> Type) rethrows -> Type {