mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fix a data race with _swiftEmptyArrayStorage's count
This commit is contained in:
@@ -750,9 +750,13 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
|
||||
_uninitializedCount: newCapacity, minimumCapacity: 0)
|
||||
p = newResult.firstElementAddress + result.capacity
|
||||
remainingCapacity = newResult.capacity - result.capacity
|
||||
newResult.firstElementAddress.moveInitialize(
|
||||
from: result.firstElementAddress, count: result.capacity)
|
||||
result.count = 0
|
||||
if !result.isEmpty {
|
||||
// This check prevents a data race writting to _swiftEmptyArrayStorage
|
||||
// Since count is always 0 there, this code does nothing anyway
|
||||
newResult.firstElementAddress.moveInitialize(
|
||||
from: result.firstElementAddress, count: result.capacity)
|
||||
result.count = 0
|
||||
}
|
||||
(result, newResult) = (newResult, result)
|
||||
}
|
||||
addWithExistingCapacity(element)
|
||||
|
||||
Reference in New Issue
Block a user