Re: objc_atomicCompareAndSwapInstanceVariable
Re: objc_atomicCompareAndSwapInstanceVariable
- Subject: Re: objc_atomicCompareAndSwapInstanceVariable
- From: Greg Parker <email@hidden>
- Date: Sat, 3 Oct 2009 02:39:57 -0700
On Oct 3, 2009, at 2:13 AM, André Berg wrote:
In <objc/objc-auto.h> I found this functions:
OBJC_GC_EXPORT BOOL objc_atomicCompareAndSwapPtr(id predicate, id
replacement, volatile id *objectLocation)
OBJC_GC_EXPORT BOOL objc_atomicCompareAndSwapInstanceVariable(id
predicate, id replacement, volatile id *objectLocation);
OBJC_GC_EXPORT BOOL objc_atomicCompareAndSwapGlobal(id predicate, id
replacement, volatile id *objectLocation);
This sounds exiting! But I couldn't find any documentation for it
other than the comment in the header.
I presume these work like the functions from libkern (<libkern/
OSAtomic.h>) ?
Can the predicate be any predicate or is it more like OSAtomic...
functions in that it must have some correlation with the value at
objectLocation (replacement will only be set as new value if
predicate and objectLocation are equal, at least that's how I
understood what "man atomic(3)" was saying about the equivalent
functions from OSAtomic)?
These are exactly like OSAtomic's compare and swap with barrier, but
for use when you're modifying GC-scanned storage. They tell the
garbage collector about the assignment, if any. (If you use the
OSAtomic functions directly with GC-scanned storage, then you can
confuse the garbage collector which may delete your objects
unexpectedly.)
And how do you pass the objectLocation of an instance variable
without accessing them directly (e.g. "obj->ivar" which will be a
hard error in the future according to compiler warnings)?
`obj->ivar` is perfectly legal, as long as you respect the ivar's
access permissions. You won't get a warning if you access the class's
own @private ivars, or its superclass's @protected ivars, or any other
class's @package or @public ivars.
--
Greg Parker email@hidden RUntime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden