Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created June 22, 2009 21:54
Show Gist options
  • Save benjamn/134214 to your computer and use it in GitHub Desktop.
Save benjamn/134214 to your computer and use it in GitHub Desktop.
extern bool compare_and_swap(void** vp, void* cmp, void* val);
template <class T>
bool CASRefs(T** vp, T* cmp, T* val)
{
if (val)
val->AddRef();
if (compare_and_swap(vp, cmp, val)) {
if (cmp)
cmp->Release();
return true;
} else {
if (val)
val->Release();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment