开发者

Atomically get value on Mac OS

I need some function to atomi开发者_如何学运维cally get int value. Something called OSAtomicGet(). Analog of g_atomic_int_get().


Dereferencing an int from a known pointer is always atomic on architectures running Mac/iStuffs. Use OSMemoryBarrier() if you need a memory barrier.

int OSAtomicGet(volatile int* value) {
   OSMemoryBarrier();
   return *value;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜