-1

I need some function to atomically get int value. Something called OSAtomicGet(). Analog of g_atomic_int_get().

shoumikhin
  • 1,327
  • 15
  • 23
  • Сounterquestion: where all the int values are stored so that you can access them with OSAtomic* API? – shoumikhin Jul 07 '10 at 16:27

1 Answers1

2

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;
}
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005