Skip to content

Commit 9d6b53c

Browse files
committed
Move locking and TLS back in to a singlular library and adjust a few signatures
1 parent 1065fae commit 9d6b53c

17 files changed

+27
-70
lines changed

stdlib/public/Observation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
#
1111
#===----------------------------------------------------------------------===#
1212

13-
add_subdirectory(Sources/_ObservationRuntime)
1413
add_subdirectory(Sources/Observation)

stdlib/public/Observation/Sources/Observation/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ set(SWIFT_OBSERVATION_SWIFT_FLAGS)
1414

1515
add_swift_target_library(swiftObservation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
1616
ImmediateTransactionModel.swift
17+
Locking.cpp
18+
Locking.swift
1719
MemberKeyPaths.swift
1820
Observable.swift
1921
ObservationRegistrar.swift
@@ -23,9 +25,10 @@ add_swift_target_library(swiftObservation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS
2325
ObservationTransactionModel.swift
2426
ObservedChanges.swift
2527
Observer.swift
28+
ThreadLocal.cpp
29+
ThreadLocal.swift
2630

2731
SWIFT_COMPILE_FLAGS
2832
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
2933
${SWIFT_OBSERVATION_SWIFT_FLAGS}
30-
SWIFT_MODULE_DEPENDS _ObservationRuntime
3134
INSTALL_IN_COMPONENT stdlib)

stdlib/public/Observation/Sources/Observation/ImmediateTransactionModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
struct ImmediateObservationTransactionModel: ObservationTransactionModel {

stdlib/public/Observation/Sources/_ObservationRuntime/Locking.swift renamed to stdlib/public/Observation/Sources/Observation/Locking.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@_silgen_name("_swift_observation_lock_size")
1514
func _lockSize() -> Int
@@ -24,7 +23,7 @@ func _lockLock(_: UnsafeRawPointer)
2423
func _lockUnlock(_: UnsafeRawPointer)
2524

2625
@available(SwiftStdlib 5.9, *)
27-
public struct ManagedCriticalState<State> {
26+
struct ManagedCriticalState<State> {
2827
final private class LockedBuffer: ManagedBuffer<State, UInt8> { }
2928

3029
private let buffer: ManagedBuffer<State, UInt8>
@@ -33,16 +32,14 @@ public struct ManagedCriticalState<State> {
3332
self.buffer = buffer
3433
}
3534

36-
public init(_ initial: State) {
37-
self.init(LockedBuffer.create(minimumCapacity: _swift_observation_lock_size()) { buffer in
35+
init(_ initial: State) {
36+
self.init(LockedBuffer.create(minimumCapacity: _lockSize()) { buffer in
3837
buffer.withUnsafeMutablePointerToElements { _lockInit(UnsafeRawPointer($0)) }
3938
return initial
4039
})
4140
}
4241

43-
@_transparent
44-
@inlinable
45-
public func withCriticalRegion<R>(
42+
func withCriticalRegion<R>(
4643
_ critical: (inout State) throws -> R
4744
) rethrows -> R {
4845
try buffer.withUnsafeMutablePointers { header, lock in
@@ -54,7 +51,7 @@ public struct ManagedCriticalState<State> {
5451
}
5552

5653
@available(SwiftStdlib 5.9, *)
57-
public protocol Deinitializable {
54+
protocol Deinitializable {
5855
func deinitialize()
5956
}
6057

@@ -65,32 +62,31 @@ extension ManagedCriticalState where State: Deinitializable {
6562
deinit {
6663
withUnsafeMutablePointers { header, lock in
6764
header.pointee.deinitialize()
68-
Lock.deinitialize(lock)
6965
}
7066
}
7167
}
7268

73-
public init(managing initial: State) {
74-
self.init(DeinitializingLockedBuffer.create(minimumCapacity: _swift_observation_lock_size()) { buffer in
69+
init(managing initial: State) {
70+
self.init(DeinitializingLockedBuffer.create(minimumCapacity: _lockSize()) { buffer in
7571
buffer.withUnsafeMutablePointerToElements { _lockInit(UnsafeRawPointer($0)) }
7672
return initial
7773
})
7874
}
7975
}
8076

8177
@available(SwiftStdlib 5.9, *)
82-
public extension ManagedCriticalState: @unchecked Sendable where State: Sendable { }
78+
extension ManagedCriticalState: @unchecked Sendable where State: Sendable { }
8379

8480
@available(SwiftStdlib 5.9, *)
8581
extension ManagedCriticalState: Hashable {
86-
public static func == (
82+
static func == (
8783
lhs: ManagedCriticalState<State>,
8884
rhs: ManagedCriticalState<State>
8985
) -> Bool {
9086
lhs.buffer === rhs.buffer
9187
}
9288

93-
public func hash(into hasher: inout Hasher) {
89+
func hash(into hasher: inout Hasher) {
9490
hasher.combine(ObjectIdentifier(buffer))
9591
}
9692
}

stdlib/public/Observation/Sources/Observation/MemberKeyPaths.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
@frozen

stdlib/public/Observation/Sources/Observation/Observable.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
public protocol Observable: Identifiable {
@@ -58,8 +57,3 @@ extension Observable {
5857
return [keyPath]
5958
}
6059
}
61-
62-
63-
64-
65-

stdlib/public/Observation/Sources/Observation/ObservationRegistrar.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
13-
@_implementationOnly import _ObservationRuntime
1412

1513
@available(SwiftStdlib 5.9, *)
1614
public struct ObservationRegistar<Subject: Observable>: @unchecked Sendable {

stdlib/public/Observation/Sources/Observation/ObservationToken.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
public struct ObservationToken: Hashable, Sendable {

stdlib/public/Observation/Sources/Observation/ObservationTracking.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
protocol ObservationTrackingEntry {

stdlib/public/Observation/Sources/Observation/ObservationTransaction.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
public struct ObservationTransaction<Subject: Observable>: Hashable, Identifiable {

stdlib/public/Observation/Sources/Observation/ObservationTransactionModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
public protocol ObservationTransactionModel {

stdlib/public/Observation/Sources/Observation/ObservedChanges.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312
import _Concurrency
1413

1514
@available(SwiftStdlib 5.9, *)

stdlib/public/Observation/Sources/Observation/Observer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@available(SwiftStdlib 5.9, *)
1514
public protocol Observer<Subject> {

stdlib/public/Observation/Sources/_ObservationRuntime/ThreadLocal.cpp renamed to stdlib/public/Observation/Sources/Observation/ThreadLocal.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,21 @@ void *_swift_observation_tls_get(uint64_t key) {
8787
#if SWIFT_TLS_PTHREAD_DIRECT
8888
return _pthread_getspecific_direct((unsigned long)key);
8989
#elif SWIFT_TLS_PTHREAD
90-
return pthread_get_specific((pthread_key_t)key);
90+
return pthread_getspecific((pthread_key_t)key);
9191
#elif SWIFT_TLS_FLS
92+
assert(key & ~0xffffffff == 0);
9293
return FlsGetValue((DWORD)key);
9394
#endif
9495
}
9596

9697
extern "C" SWIFT_CC(swift)
97-
_swift_observation_tls_set(uint64_t key, void *value) {
98+
void _swift_observation_tls_set(uint64_t key, void *value) {
9899
#if SWIFT_TLS_PTHREAD_DIRECT
99-
return _pthread_setspecific_direct((unsigned long)key, value);
100+
_pthread_setspecific_direct((unsigned long)key, value);
100101
#elif SWIFT_TLS_PTHREAD
101-
return pthread_set_specific((pthread_key_t)key, value);
102+
pthread_setspecific((pthread_key_t)key, value);
102103
#elif SWIFT_TLS_FLS
103-
return FlsSetValue((DWORD)key, value);
104+
assert(key & ~0xffffffff == 0);
105+
FlsSetValue((DWORD)key, value);
104106
#endif
105107
}

stdlib/public/Observation/Sources/_ObservationRuntime/ThreadLocal.swift renamed to stdlib/public/Observation/Sources/Observation/ThreadLocal.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import Swift
1312

1413
@_silgen_name("_swift_observation_tracking_key")
1514
func _trackingKey() -> UInt64
@@ -24,19 +23,20 @@ func _tlsGet(_ key: UInt64) -> UnsafeMutableRawPointer?
2423
func _tlsSet(_ key: UInt64, _ value: UnsafeMutableRawPointer?)
2524

2625
@available(SwiftStdlib 5.9, *)
27-
public struct ThreadLocal {
28-
public struct Key {
26+
struct ThreadLocal {
27+
struct Key {
2928
var raw: UInt64
3029

3130
init(raw: UInt64) {
3231
self.raw = raw
3332
}
33+
34+
static let trackingKey = Key(raw: _trackingKey())
35+
static let transactionKey = Key(raw: _transactionKey())
3436
}
3537

36-
public static let trackingKey = ThreadLocal.Key(raw: _trackingKey())
37-
public static let transactionKey = ThreadLocal.Key(raw: _transactionKey())
3838

39-
public static subscript(_ key: Key) -> UnsafeMutableRawPointer? {
39+
static subscript(_ key: Key) -> UnsafeMutableRawPointer? {
4040
get {
4141
return _tlsGet(key.raw)
4242
}

stdlib/public/Observation/Sources/_ObservationRuntime/CMakeLists.txt

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)