Added swift_retainCount to EmbeddedRuntime.swift

Fixes test/embedded/concurrency-actors.swift
This commit is contained in:
Mykola Pokhylets
2024-08-19 23:41:33 +02:00
parent 50b1313175
commit 0412597731
2 changed files with 15 additions and 1 deletions

View File

@@ -204,6 +204,14 @@ FUNCTION(CopyPOD, swift_copyPOD, C_CC, AlwaysAvailable,
EFFECT(NoEffect), EFFECT(NoEffect),
UNKNOWN_MEMEFFECTS) UNKNOWN_MEMEFFECTS)
// size_t swift_retainCount(void *ptr);
FUNCTION(NativeRetainCount, swift_retainCount, C_CC, AlwaysAvailable,
RETURNS(SizeTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind, WillReturn),
EFFECT(RefCounting),
UNKNOWN_MEMEFFECTS)
// void *swift_retain(void *ptr); // void *swift_retain(void *ptr);
FUNCTION(NativeStrongRetain, swift_retain, C_CC, AlwaysAvailable, FUNCTION(NativeStrongRetain, swift_retain, C_CC, AlwaysAvailable,
RETURNS(RefCountedPtrTy), RETURNS(RefCountedPtrTy),

View File

@@ -309,7 +309,13 @@ public func swift_bridgeObjectRelease_n(object: Builtin.RawPointer, n: UInt32) {
swift_release_n(object: untaggedObject, n: n) swift_release_n(object: untaggedObject, n: n)
} }
@_cdecl("swift_retainCount")
public func swift_retainCount(object: Builtin.RawPointer) -> Int {
if !isValidPointerForNativeRetain(object: object) { return 0 }
let o = UnsafeMutablePointer<HeapObject>(object)
let refcount = refcountPointer(for: o)
return loadAcquire(refcount) & HeapObject.refcountMask
}
/// Refcount helpers /// Refcount helpers