Skip to content

Instantly share code, notes, and snippets.

@OdNairy
Created May 14, 2013 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OdNairy/5575157 to your computer and use it in GitHub Desktop.
Save OdNairy/5575157 to your computer and use it in GitHub Desktop.
Реализация retain
- (id)retain
__attribute__((aligned(16)))
{
if (OBJC_IS_TAGGED_PTR(self)) return self;
SideTable *table = SideTable::tableForPointer(self);
if (OSSpinLockTry(&table->slock)) {
table->refcnts[DISGUISE(self)] += 2;
OSSpinLockUnlock(&table->slock);
return self;
}
return _objc_rootRetain_slow(self);
}
id
_objc_rootRetain_slow(id obj)
{
SideTable *table = SideTable::tableForPointer(obj);
OSSpinLockLock(&table->slock);
table->refcnts[DISGUISE(obj)] += 2;
OSSpinLockUnlock(&table->slock);
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment