Skip to content

Commit 1c9d8d2

Browse files
committed
[concurrency] Avoid capacity in Deque on OpenBSD.
Deque creates a new ManagedBuffer when growing the underlying storage for its elements. It sets the capacity in the header object, however it initializes that field with ManagedBuffer.capacity. ManagedBuffer.capacity is marked unavailable on OpenBSD because ManagedBuffer unavoidably depends on malloc introspection which is unavailable on this platform. Obviously, we could mark the whole class as unavailable, but we don't need to do anything so drastic since it appears though that Deque doesn't unavoidably need this introspection. Therefore, on OpenBSD, just use `minimumCapacity` when creating a new ManagedBuffer when growing and moving elements.
1 parent 069e51d commit 1c9d8d2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

stdlib/public/Concurrency/Deque.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ struct _Deque<Element> {
228228
let object = _Storage._DequeBuffer.create(
229229
minimumCapacity: minimumCapacity,
230230
makingHeaderWith: {
231-
_Storage._Header(
232-
capacity: $0.capacity,
231+
#if os(OpenBSD)
232+
let capacity = minimumCapacity
233+
#else
234+
let capacity = $0.capacity
235+
#endif
236+
return _Storage._Header(
237+
capacity: capacity,
233238
count: count,
234239
startSlot: .zero)
235240
})

0 commit comments

Comments
 (0)