Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created November 18, 2011 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/1376139 to your computer and use it in GitHub Desktop.
Save piscisaureus/1376139 to your computer and use it in GitHub Desktop.
/* The low-order bit of lock->Ptr is set when the lock is held. If _only_ */
/* the low-order bit is set, the lock is held in exclusive mode. */
BOOLEAN TryAcquireSRWLockExclusive(SRWLOCK* lock) {
if (sizeof lock->Ptr == sizeof LONG) {
return InterlockedBitTestAndSet((LONG*) lock->Ptr, 0);
} else if (sizeof lock->Ptr == sizeof LONG64) {
return InterlockedBitTestAndSet64((LONG64*) lock->Ptr, 0);
} else {
abort();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment