Files
swift-mirror/stdlib/public/Synchronization/Mutex/WindowsImpl.swift
Allan Shortlidge 008efc432f stdlib: Fix missing unsafe operators in more places.
Add `unsafe` where it is still missing. I missed these in previous passes due
to conditional compilation.
2025-06-22 18:46:57 -07:00

52 lines
1.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import WinSDK.core.synch
@available(SwiftStdlib 6.0, *)
@frozen
@safe
@_staticExclusiveOnly
public struct _MutexHandle: ~Copyable {
@usableFromInline
let value: _Cell<SRWLOCK>
@available(SwiftStdlib 6.0, *)
@_alwaysEmitIntoClient
@_transparent
public init() {
unsafe value = _Cell(SRWLOCK())
}
@available(SwiftStdlib 6.0, *)
@_alwaysEmitIntoClient
@_transparent
internal borrowing func _lock() {
unsafe AcquireSRWLockExclusive(value._address)
}
@available(SwiftStdlib 6.0, *)
@_alwaysEmitIntoClient
@_transparent
internal borrowing func _tryLock() -> Bool {
// Windows BOOLEAN gets imported as 'UInt8'...
unsafe TryAcquireSRWLockExclusive(value._address) != 0
}
@available(SwiftStdlib 6.0, *)
@_alwaysEmitIntoClient
@_transparent
internal borrowing func _unlock() {
unsafe ReleaseSRWLockExclusive(value._address)
}
}