Skip to content

Commit 88f5b7a

Browse files
committed
Windows support
1 parent 9b60f8c commit 88f5b7a

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build](https://github.com/swhitty/FlyingFox/actions/workflows/build.yml/badge.svg)](https://github.com/swhitty/AllocatedLock/actions/workflows/build.yml)
22
[![Codecov](https://codecov.io/gh/swhitty/FlyingFox/graphs/badge.svg)](https://codecov.io/gh/swhitty/AllocatedLock)
3-
[![Platforms](https://img.shields.io/badge/platforms-iOS%20|%20Mac%20|%20tvOS%20|%20Linux%20)](https://github.com/swhitty/AllocatedLock/blob/main/Package.swift)
3+
[![Platforms](https://img.shields.io/badge/platforms-iOS%20|%20Mac%20|%20tvOS%20|%20Linux%20|%20Windows-lightgray.svg)](https://github.com/swhitty/AllocatedLock/blob/main/Package.swift)
44
[![Swift 5.8](https://img.shields.io/badge/swift-5.5%20–%205.8-red.svg?style=flat)](https://developer.apple.com/swift)
55
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT)
66
[![Twitter](https://img.shields.io/badge/twitter-@simonwhitty-blue.svg)](http://twitter.com/simonwhitty)
@@ -13,12 +13,11 @@
1313

1414
AllocatedLock can be installed by using Swift Package Manager.
1515

16-
**Note:** AllocatedLock requires Swift 5.7 on Xcode 14+. It runs on iOS 13+, tvOS 13+, macOS 10.15+ and Linux.
17-
16+
**Note:** AllocatedLock requires Swift 5.7 on Xcode 14+. It runs on iOS 13+, tvOS 13+, macOS 10.15+, Linux and Windows.
1817
To install using Swift Package Manager, add this to the `dependencies:` section in your Package.swift file:
1918

2019
```swift
21-
.package(url: "https://github.com/swhitty/AllocatedLock.git", .upToNextMajor(from: "0.0.1"))
20+
.package(url: "https://github.com/swhitty/AllocatedLock.git", .upToNextMajor(from: "0.0.2"))
2221
```
2322

2423
# Usage

Sources/AllocatedLock.swift

+31
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,35 @@ extension AllocatedLock {
149149
}
150150
}
151151
}
152+
153+
#elseif canImport(WinSDK)
154+
@_implementationOnly import ucrt
155+
@_implementationOnly import WinSDK
156+
157+
extension AllocatedLock {
158+
@usableFromInline
159+
final class Storage {
160+
private let _lock: UnsafeMutablePointer<SRWLOCK>
161+
162+
@usableFromInline
163+
var state: State
164+
165+
init(initialState: State) {
166+
self._lock = .allocate(capacity: 1)
167+
InitializeSRWLock(self._lock)
168+
self.state = initialState
169+
}
170+
171+
@usableFromInline
172+
func lock() {
173+
AcquireSRWLockExclusive(_lock)
174+
}
175+
176+
@usableFromInline
177+
func unlock() {
178+
ReleaseSRWLockExclusive(_lock)
179+
}
180+
}
181+
}
182+
152183
#endif

0 commit comments

Comments
 (0)