[embedded] Add a more detailed explaining comment to swift_release_n_

This commit is contained in:
Kuba Mracek
2024-09-16 10:37:40 -07:00
parent c8cbf06522
commit b4431db2c5

View File

@@ -292,7 +292,14 @@ func swift_release_n_(object: UnsafeMutablePointer<HeapObject>?, n: UInt32) {
let resultingRefcount = subFetchAcquireRelease(refcount, n: Int(n)) & HeapObject.refcountMask
if resultingRefcount == 0 {
// Set the refcount to immortalRefCount before calling the object destroyer
// to prevent future retains/releases from having any effect.
// to prevent future retains/releases from having any effect. Unlike the
// full Swift runtime, we don't track the refcount inside deinit, so we
// won't be able to detect escapes or over-releases of `self` in deinit. We
// might want to reconsider that in the future.
//
// There can only be one thread with a reference at this point (because
// we're releasing the last existing reference), so a relaxed store is
// enough.
storeRelaxed(refcount, newValue: HeapObject.immortalRefCount)
_swift_embedded_invoke_heap_object_destroy(object)