Skip to content

Commit 36b6b96

Browse files
committed
Synchronization: Add errno to some linux lock fatalErrors
In the comments it's stated that these errnos can't really occur for the implementation, but unfortunately they have been seen in some scenarios. To aide in debugging, it'd be nice to at least have the errno in the error message.
1 parent a69dbb3 commit 36b6b96

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stdlib/public/Synchronization/Mutex/LinuxImpl.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ extension _MutexHandle {
137137
// Block until an equivalent '_futexUnlock' has been called by the owner.
138138
// This returns '0' on success which means the kernel has acquired the
139139
// lock for us.
140-
switch storage._futexLock() {
140+
let lockResult = storage._futexLock()
141+
switch lockResult {
141142
case 0:
142143
// Locked!
143144
return
@@ -191,7 +192,7 @@ extension _MutexHandle {
191192
// ESRCH - "The thread ID in the futex word at uaddr does not exist."
192193
default:
193194
// TODO: Replace with a colder function / one that takes a StaticString
194-
fatalError("Unknown error occurred while attempting to acquire a Mutex")
195+
fatalError("Unknown error occurred while attempting to acquire a Mutex: \(lockResult)")
195196
}
196197
}
197198
}
@@ -308,7 +309,8 @@ extension _MutexHandle {
308309
@usableFromInline
309310
internal borrowing func _unlockSlow() {
310311
while true {
311-
switch storage._futexUnlock() {
312+
let unlockResult = storage._futexUnlock()
313+
switch unlockResult {
312314
case 0:
313315
// Unlocked!
314316
return
@@ -360,7 +362,7 @@ extension _MutexHandle {
360362
// space.)"
361363
default:
362364
// TODO: Replace with a colder function / one that takes a StaticString
363-
fatalError("Unknown error occurred while attempting to release a Mutex")
365+
fatalError("Unknown error occurred while attempting to release a Mutex: \(unlockResult)")
364366
}
365367
}
366368
}

0 commit comments

Comments
 (0)