Skip to content

Commit 5b88226

Browse files
committed
Update lock type
1 parent a99b841 commit 5b88226

File tree

3 files changed

+99
-9
lines changed

3 files changed

+99
-9
lines changed

Package.resolved

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/UUIDV7/UUIDV7+Dependencies.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
/// See ``Dependencies/DependencyValues/uuidv7`` for more information.
8080
public struct UUIDV7Generator: Sendable {
8181
private let uuid: @Sendable () -> UUIDV7
82-
82+
8383
/// Initializes a UUID generator that generates a ``UUIDV7`` from a closure.
8484
///
8585
/// - Parameter uuid: A closure that returns a `UUIDV7` when called.
@@ -155,7 +155,7 @@
155155
public static func incrementing(
156156
from timeIntervalSince1970: @autoclosure @escaping @Sendable () -> TimeInterval
157157
) -> Self {
158-
let count = Lock(UInt32(0))
158+
let count = _UUIDV7Lock(UInt32(0))
159159
return Self {
160160
count.withLock { count in
161161
defer { count += 1 }
@@ -179,7 +179,7 @@
179179
@Dependency(\.uuidv7) var uuidv7
180180
return .v7(uuidv7)
181181
}
182-
182+
183183
/// A generator that returns raw UUIDs generated by a specified ``UUIDV7Generator``.
184184
///
185185
/// - Parameter generator: The generator to use.

Sources/UUIDV7/UUIDV7.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ extension UUIDV7 {
476476

477477
// MARK: - Lock
478478

479-
private struct Lock<State> {
479+
struct _UUIDV7Lock<State> {
480480
private let buffer: ManagedBuffer<State, PlatformLock.Primitive>
481481

482482
init(_ initial: State) {
@@ -487,15 +487,15 @@ private struct Lock<State> {
487487
}
488488
}
489489

490-
extension Lock {
490+
extension _UUIDV7Lock {
491491
private final class LockedBuffer: ManagedBuffer<State, PlatformLock.Primitive> {
492492
deinit {
493493
self.withUnsafeMutablePointerToElements { PlatformLock.deinitialize($0) }
494494
}
495495
}
496496
}
497497

498-
extension Lock {
498+
extension _UUIDV7Lock {
499499
func withLock<R>(_ critical: (inout State) throws -> sending R) rethrows -> R {
500500
try self.buffer.withUnsafeMutablePointers { header, lock in
501501
PlatformLock.lock(lock)
@@ -506,7 +506,7 @@ extension Lock {
506506
}
507507

508508
// NB: This is safe because all mutable state is accessed only while holding `PlatformLock`.
509-
extension Lock: @unchecked Sendable where State: Sendable {}
509+
extension _UUIDV7Lock: @unchecked Sendable where State: Sendable {}
510510

511511
// MARK: - PlatformLock
512512

@@ -584,7 +584,7 @@ private enum PlatformLock {
584584

585585
/// See https://www.rfc-editor.org/rfc/rfc9562.html#section-6.2-5.1
586586
private struct MonotonicityState: Sendable {
587-
static let current = Lock(Self())
587+
static let current = _UUIDV7Lock(Self())
588588

589589
private var previousTimestamp = UInt64(0)
590590
private var sequence = UInt16(0)
@@ -620,7 +620,7 @@ extension MonotonicityState {
620620
// MARK: - RandomUUIDBytesGenerator
621621

622622
private struct RandomUUIDBytesGenerator {
623-
static nonisolated(unsafe) let shared = Lock(Self())
623+
static nonisolated(unsafe) let shared = _UUIDV7Lock(Self())
624624

625625
private static let cacheSize = 256
626626

0 commit comments

Comments
 (0)