It is currently Wed Dec 13, 2017 2:47 am

Mulle kybernetiK Optimization

Forum for Optimizations around Cocoa and Mac OS X

Article 4.1: Atomic Operations

Discussion about the <a href="http://www.mulle-kybernetik.com/artikel/Optimization">Optimizing Objective-C Article Series</a>
User avatar
 
Posts: 42
Joined: Fri Aug 06, 2004 9:20 am
Location: Bochum
Website: http://www.mulle-kybernetik.com/weblog

Article 4.1: Atomic Operations

Post by Nat! » Wed Sep 15, 2004 12:56 am

Discusssion thread for this specific optimization article.

 
Posts: 1
Joined: Wed Jan 26, 2005 11:27 am

Post by phip » Wed Jan 26, 2005 11:55 am

After reading this article, I wondered if/why didn't Apple provide atomic functions. After some digging, I found them. They are located in CoreServices.framework, in a header called DriverSynchronization.h. They are all listed as "Available Mac OS X in version 10.0 and later"

What's the verdict on these functions? Probably not as fast as the roll-your-own versions, since they aren't inlined and would imply a dyld_stub call, right? On the other hand, Apple may have a few tricks to make it safer. Hmm...

Here are the 32 bit prototypes. There are also 8 and 16 bit variations, though mask and amount are always 32.

Code: Select all

extern SInt32 IncrementAtomic(SInt32 * value);
extern SInt32 DecrementAtomic(SInt32 * value);
extern SInt32 AddAtomic(SInt32 amount, SInt32 * value);
extern UInt32 BitAndAtomic(UInt32 mask, UInt32 * value);
extern UInt32 BitOrAtomic(UInt32 mask, UInt32 * value);
extern UInt32 BitXorAtomic(UInt32 mask, UInt32 * value);

User avatar
 
Posts: 42
Joined: Fri Aug 06, 2004 9:20 am
Location: Bochum
Website: http://www.mulle-kybernetik.com/weblog

Post by Nat! » Thu Jan 27, 2005 12:13 pm

phip wrote:What's the verdict on these functions? Probably not as fast as the roll-your-own versions, since they aren't inlined and would imply a dyld_stub call, right?


That'd be my opinion too. Faster than using a lock, probably quite a bit, because there is no need <b>sync</b>, but quite a bit slower than using the inlined method.

My gut feeling is, that if you choose atomic increment/decrement over locking, you will be calling it that often, that inlining will seem very tempting.


Return to “Article Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest