Add refcount accessor function.

main
David Chisnall 8 years ago
parent e5b4468867
commit 12b820cb99

@ -175,6 +175,13 @@ static const long weak_mask = ((size_t)1)<<((sizeof(size_t)*8)-1);
*/ */
static const long refcount_mask = ~weak_mask; static const long refcount_mask = ~weak_mask;
size_t object_getRetainCount_np(id obj)
{
uintptr_t *refCount = ((uintptr_t*)obj) - 1;
uintptr_t refCountVal = __sync_fetch_and_add(refCount, 0);
return (((size_t)refCountVal) & refcount_mask) + 1;
}
id objc_retain_fast_np(id obj) id objc_retain_fast_np(id obj)
{ {
uintptr_t *refCount = ((uintptr_t*)obj) - 1; uintptr_t *refCount = ((uintptr_t*)obj) - 1;

@ -111,6 +111,10 @@ void objc_release_fast_np(id obj) OBJC_NONPORTABLE;
* ARC-compatible classes. * ARC-compatible classes.
*/ */
BOOL objc_release_fast_no_destroy_np(id obj) OBJC_NONPORTABLE; BOOL objc_release_fast_no_destroy_np(id obj) OBJC_NONPORTABLE;
/**
* Returns the retain count of an object.
*/
size_t object_getRetainCount_np(id obj) OBJC_NONPORTABLE;
/** /**
* Releases an object. Equivalent to [obj release]. * Releases an object. Equivalent to [obj release].
*/ */

Loading…
Cancel
Save