Skip to content

Commit 66ec7ab

Browse files
committed
Underscore some things, add explicit internal
Fix some compile issues
1 parent fbfb218 commit 66ec7ab

File tree

13 files changed

+163
-127
lines changed

13 files changed

+163
-127
lines changed

stdlib/public/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ set(sources
1717
SwiftStdbool.h
1818
SwiftStddef.h
1919
SwiftStdint.h
20-
SynchronizationShims.h
2120
System.h
2221
Target.h
2322
ThreadLocalStorage.h
2423
UnicodeData.h
2524
Visibility.h
2625
_SwiftConcurrency.h
2726
_SwiftDistributed.h
27+
_SynchronizationShims.h
2828

2929
module.modulemap
3030
)

stdlib/public/SwiftShims/swift/shims/SynchronizationShims.h renamed to stdlib/public/SwiftShims/swift/shims/_SynchronizationShims.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "SwiftStdint.h"
1818

1919
#if defined(__linux__)
20+
#include <errno.h>
2021
#include <linux/futex.h>
2122
#include <sys/syscall.h>
2223
#include <unistd.h>
@@ -31,18 +32,36 @@ static inline __swift_uint32_t _swift_stdlib_gettid() {
3132
return tid;
3233
}
3334

34-
static inline __swift_bool _swift_stdlib_futex_lock(__swift_uint32_t *lock) {
35-
return syscall(SYS_futex, lock, FUTEX_LOCK_PI_PRIVATE,
36-
/* val */ 0, // this value is ignored by this futex op
37-
/* timeout */ NULL); // block indefinitely
35+
static inline __swift_uint32_t _swift_stdlib_futex_lock(__swift_uint32_t *lock) {
36+
int ret = syscall(SYS_futex, lock, FUTEX_LOCK_PI_PRIVATE,
37+
/* val */ 0, // this value is ignored by this futex op
38+
/* timeout */ NULL); // block indefinitely
39+
40+
if (ret == 0) {
41+
return ret;
42+
}
43+
44+
return errno;
3845
}
3946

40-
static inline __swift_bool _swift_stdlib_futex_trylock(__swift_uint32_t *lock) {
41-
return syscall(SYS_futex, lock, FUTEX_TRYLOCK_PI);
47+
static inline __swift_uint32_t _swift_stdlib_futex_trylock(__swift_uint32_t *lock) {
48+
int ret = syscall(SYS_futex, lock, FUTEX_TRYLOCK_PI);
49+
50+
if (ret == 0) {
51+
return ret;
52+
}
53+
54+
return errno;
4255
}
4356

44-
static inline __swift_bool _swift_stdlib_futex_unlock(__swift_uint32_t *lock) {
45-
return syscall(SYS_futex, lock, FUTEX_UNLOCK_PI_PRIVATE);
57+
static inline __swift_uint32_t _swift_stdlib_futex_unlock(__swift_uint32_t *lock) {
58+
int ret = syscall(SYS_futex, lock, FUTEX_UNLOCK_PI_PRIVATE);
59+
60+
if (ret == 0) {
61+
return ret;
62+
}
63+
64+
return errno;
4665
}
4766

4867
#endif // defined(__linux__)

stdlib/public/SwiftShims/swift/shims/module.modulemap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module SwiftOverlayShims {
3232
export *
3333
}
3434

35-
module SynchronizationShims {
36-
header "SynchronizationShims.h"
35+
module _SynchronizationShims {
36+
header "_SynchronizationShims.h"
3737
export *
3838
}

stdlib/public/Synchronization/Atomics/Atomic.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public struct Atomic<Value: AtomicRepresentable>: ~Copyable {
2121
@available(SwiftStdlib 6.0, *)
2222
@_alwaysEmitIntoClient
2323
@_transparent
24-
var address: UnsafeMutablePointer<Value.AtomicRepresentation> {
25-
UnsafeMutablePointer<Value.AtomicRepresentation>(rawAddress)
24+
var _address: UnsafeMutablePointer<Value.AtomicRepresentation> {
25+
UnsafeMutablePointer<Value.AtomicRepresentation>(_rawAddress)
2626
}
2727

2828
@available(SwiftStdlib 6.0, *)
2929
@_alwaysEmitIntoClient
3030
@_transparent
31-
var rawAddress: Builtin.RawPointer {
31+
var _rawAddress: Builtin.RawPointer {
3232
Builtin.unprotectedAddressOfBorrow(self)
3333
}
3434

@@ -39,7 +39,7 @@ public struct Atomic<Value: AtomicRepresentable>: ~Copyable {
3939
@_alwaysEmitIntoClient
4040
@_transparent
4141
public init(_ initialValue: consuming Value) {
42-
address.initialize(to: Value.encodeAtomicRepresentation(initialValue))
42+
_address.initialize(to: Value.encodeAtomicRepresentation(initialValue))
4343
}
4444

4545
// Deinit's can't be marked @_transparent. Do these things need all of these
@@ -48,10 +48,10 @@ public struct Atomic<Value: AtomicRepresentable>: ~Copyable {
4848
@_alwaysEmitIntoClient
4949
@inlinable
5050
deinit {
51-
let oldValue = Value.decodeAtomicRepresentation(address.pointee)
51+
let oldValue = Value.decodeAtomicRepresentation(_address.pointee)
5252
_ = consume oldValue
5353

54-
address.deinitialize(count: 1)
54+
_address.deinitialize(count: 1)
5555
}
5656
}
5757

stdlib/public/Synchronization/Atomics/AtomicBool.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,31 @@ extension Atomic where Value == Bool {
9393
let original = switch ordering {
9494
case .relaxed:
9595
Builtin.atomicrmw_and_monotonic_Int8(
96-
rawAddress,
96+
_rawAddress,
9797
builtinOperand
9898
)
9999

100100
case .acquiring:
101101
Builtin.atomicrmw_and_acquire_Int8(
102-
rawAddress,
102+
_rawAddress,
103103
builtinOperand
104104
)
105105

106106
case .releasing:
107107
Builtin.atomicrmw_and_release_Int8(
108-
rawAddress,
108+
_rawAddress,
109109
builtinOperand
110110
)
111111

112112
case .acquiringAndReleasing:
113113
Builtin.atomicrmw_and_acqrel_Int8(
114-
rawAddress,
114+
_rawAddress,
115115
builtinOperand
116116
)
117117

118118
case .sequentiallyConsistent:
119119
Builtin.atomicrmw_and_seqcst_Int8(
120-
rawAddress,
120+
_rawAddress,
121121
builtinOperand
122122
)
123123

@@ -151,31 +151,31 @@ extension Atomic where Value == Bool {
151151
let original = switch ordering {
152152
case .relaxed:
153153
Builtin.atomicrmw_or_monotonic_Int8(
154-
rawAddress,
154+
_rawAddress,
155155
builtinOperand
156156
)
157157

158158
case .acquiring:
159159
Builtin.atomicrmw_or_acquire_Int8(
160-
rawAddress,
160+
_rawAddress,
161161
builtinOperand
162162
)
163163

164164
case .releasing:
165165
Builtin.atomicrmw_or_release_Int8(
166-
rawAddress,
166+
_rawAddress,
167167
builtinOperand
168168
)
169169

170170
case .acquiringAndReleasing:
171171
Builtin.atomicrmw_or_acqrel_Int8(
172-
rawAddress,
172+
_rawAddress,
173173
builtinOperand
174174
)
175175

176176
case .sequentiallyConsistent:
177177
Builtin.atomicrmw_or_seqcst_Int8(
178-
rawAddress,
178+
_rawAddress,
179179
builtinOperand
180180
)
181181

@@ -209,31 +209,31 @@ extension Atomic where Value == Bool {
209209
let original = switch ordering {
210210
case .relaxed:
211211
Builtin.atomicrmw_xor_monotonic_Int8(
212-
rawAddress,
212+
_rawAddress,
213213
builtinOperand
214214
)
215215

216216
case .acquiring:
217217
Builtin.atomicrmw_xor_acquire_Int8(
218-
rawAddress,
218+
_rawAddress,
219219
builtinOperand
220220
)
221221

222222
case .releasing:
223223
Builtin.atomicrmw_xor_release_Int8(
224-
rawAddress,
224+
_rawAddress,
225225
builtinOperand
226226
)
227227

228228
case .acquiringAndReleasing:
229229
Builtin.atomicrmw_xor_acqrel_Int8(
230-
rawAddress,
230+
_rawAddress,
231231
builtinOperand
232232
)
233233

234234
case .sequentiallyConsistent:
235235
Builtin.atomicrmw_xor_seqcst_Int8(
236-
rawAddress,
236+
_rawAddress,
237237
builtinOperand
238238
)
239239

stdlib/public/Synchronization/Atomics/AtomicIntegers.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,20 @@ extension Atomic where Value == ${intType} {
120120
% if intType == "Int" or intType == "UInt":
121121
#if _pointerBitWidth(_64)
122122
Builtin.atomicrmw_${atomicOperationName(intType, builtinName)}_${llvmOrder}_Int64(
123-
rawAddress,
123+
_rawAddress,
124124
operand._value
125125
)
126126
#elseif _pointerBitWidth(_32)
127127
Builtin.atomicrmw_${atomicOperationName(intType, builtinName)}_${llvmOrder}_Int32(
128-
rawAddress,
128+
_rawAddress,
129129
operand._value
130130
)
131131
#else
132132
#error("Unsupported platform")
133133
#endif
134134
% else:
135135
Builtin.atomicrmw_${atomicOperationName(intType, builtinName)}_${llvmOrder}_Int${bits}(
136-
rawAddress,
136+
_rawAddress,
137137
operand._value
138138
)
139139
% end

stdlib/public/Synchronization/Atomics/AtomicStorage.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension Atomic where Value.AtomicRepresentation == ${type} {
5353
let result = switch ordering {
5454
% for (name, api, doc, llvm) in loadOrderings:
5555
case .${name}:
56-
Builtin.atomicload_${llvm}_Int${size}(rawAddress)
56+
Builtin.atomicload_${llvm}_Int${size}(_rawAddress)
5757
% end
5858

5959
default:
@@ -87,7 +87,7 @@ extension Atomic where Value.AtomicRepresentation == ${type} {
8787
% for (name, api, doc, llvm) in storeOrderings:
8888
case .${name}:
8989
Builtin.atomicstore_${llvm}_Int${size}(
90-
rawAddress,
90+
_rawAddress,
9191
Value.encodeAtomicRepresentation(desired)._storage
9292
)
9393
% end
@@ -123,7 +123,7 @@ extension Atomic where Value.AtomicRepresentation == ${type} {
123123
let result = switch ordering {
124124
% for (name, api, _, llvm, _) in updateOrderings:
125125
case .${name}:
126-
Builtin.atomicrmw_xchg_${llvm}_Int${size}(rawAddress, desired)
126+
Builtin.atomicrmw_xchg_${llvm}_Int${size}(_rawAddress, desired)
127127
% end
128128

129129
default:
@@ -229,7 +229,7 @@ extension Atomic where Value.AtomicRepresentation == ${type} {
229229
% for (failureName, _, _, failureLLVM) in loadOrderings:
230230
case (.${successName}, .${failureName}):
231231
Builtin.cmpxchg_${actualOrders(successLLVM, failureLLVM)}_Int${size}(
232-
rawAddress,
232+
_rawAddress,
233233
expected,
234234
desired
235235
)
@@ -359,7 +359,7 @@ extension Atomic where Value.AtomicRepresentation == ${type} {
359359
% for (failureName, _, _, failureLLVM) in loadOrderings:
360360
case (.${successName}, .${failureName}):
361361
Builtin.cmpxchg_${actualOrders(successLLVM, failureLLVM)}_weak_Int${size}(
362-
rawAddress,
362+
_rawAddress,
363363
expected,
364364
desired
365365
)

stdlib/public/Synchronization/Cell.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ internal struct _Cell<Value: ~Copyable>: ~Copyable {
2020
@available(SwiftStdlib 6.0, *)
2121
@_alwaysEmitIntoClient
2222
@_transparent
23-
var address: UnsafeMutablePointer<Value> {
24-
UnsafeMutablePointer<Value>(rawAddress)
23+
internal var _address: UnsafeMutablePointer<Value> {
24+
UnsafeMutablePointer<Value>(_rawAddress)
2525
}
2626

2727
@available(SwiftStdlib 6.0, *)
2828
@_alwaysEmitIntoClient
2929
@_transparent
30-
var rawAddress: Builtin.RawPointer {
30+
internal var _rawAddress: Builtin.RawPointer {
3131
#if $BuiltinAddressOfRawLayout
3232
Builtin.addressOfRawLayout(self)
3333
#else
@@ -38,14 +38,14 @@ internal struct _Cell<Value: ~Copyable>: ~Copyable {
3838
@available(SwiftStdlib 6.0, *)
3939
@_alwaysEmitIntoClient
4040
@_transparent
41-
init(_ initialValue: consuming Value) {
42-
address.initialize(to: initialValue)
41+
internal init(_ initialValue: consuming Value) {
42+
_address.initialize(to: initialValue)
4343
}
4444

4545
@available(SwiftStdlib 6.0, *)
4646
@_alwaysEmitIntoClient
4747
@inlinable
4848
deinit {
49-
address.deinitialize(count: 1)
49+
_address.deinitialize(count: 1)
5050
}
5151
}

stdlib/public/Synchronization/Mutex/DarwinImpl.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,40 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Builtin
1413
import Darwin
1514

1615
@available(SwiftStdlib 6.0, *)
1716
@frozen
18-
@usableFromInline
1917
@_staticExclusiveOnly
20-
internal struct _MutexHandle: ~Copyable {
18+
public struct _MutexHandle: ~Copyable {
2119
@usableFromInline
2220
let value: _Cell<os_unfair_lock>
2321

2422
@available(SwiftStdlib 6.0, *)
2523
@_alwaysEmitIntoClient
2624
@_transparent
27-
init() {
25+
public init() {
2826
value = _Cell(os_unfair_lock())
2927
}
3028

3129
@available(SwiftStdlib 6.0, *)
3230
@_alwaysEmitIntoClient
3331
@_transparent
34-
borrowing func lock() {
35-
os_unfair_lock_lock(value.address)
32+
internal borrowing func _lock() {
33+
os_unfair_lock_lock(value._address)
3634
}
3735

3836
@available(SwiftStdlib 6.0, *)
3937
@_alwaysEmitIntoClient
4038
@_transparent
41-
borrowing func tryLock() -> Bool {
42-
os_unfair_lock_trylock(value.address)
39+
internal borrowing func _tryLock() -> Bool {
40+
os_unfair_lock_trylock(value._address)
4341
}
4442

4543
@available(SwiftStdlib 6.0, *)
4644
@_alwaysEmitIntoClient
4745
@_transparent
48-
borrowing func unlock() {
49-
os_unfair_lock_unlock(value.address)
46+
internal borrowing func _unlock() {
47+
os_unfair_lock_unlock(value._address)
5048
}
5149
}

0 commit comments

Comments
 (0)