DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
C Concurrency Less Big Fail
int64_t AddAndGetAtomic(Object *o, int64_t amount) {
int64_t oldval;
int64_t returnval;
bool success = 0;
do {
oldval = o->counter;
returnval = oldval + amount;
success = OSAtomicCompareAndSwap64(oldval, returnval, &(o->counter);
} while (success == 0);
return returnval;
}




