Skip to content

Instantly share code, notes, and snippets.

@YogevSitton-zz
Created April 24, 2017 12:37
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 YogevSitton-zz/08f6901a06b957704d9a4fc2c2a856df to your computer and use it in GitHub Desktop.
Save YogevSitton-zz/08f6901a06b957704d9a4fc2c2a856df to your computer and use it in GitHub Desktop.
reallySetProperty
static inline void reallySetProperty(id self, SEL _cmd, id newValue,
ptrdiff_t offset, bool atomic, bool copy, bool mutableCopy)
{
id oldValue;
id *slot = (id*) ((char*)self + offset);
if (copy) {
newValue = [newValue copyWithZone:NULL];
} else if (mutableCopy) {
newValue = [newValue mutableCopyWithZone:NULL];
} else {
if (*slot == newValue) return;
newValue = objc_retain(newValue);
}
if (!atomic) {
oldValue = *slot;
*slot = newValue;
} else {
spin_lock_t *slotlock = &PropertyLocks[GOODHASH(slot)];
_spin_lock(slotlock);
oldValue = *slot;
*slot = newValue;
_spin_unlock(slotlock);
}
objc_release(oldValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment