Skip to content

Instantly share code, notes, and snippets.

@arichardson
Created March 22, 2018 17:28
Show Gist options
  • Save arichardson/2d8c45d03c2c56bdc4c0c9d4f5b51932 to your computer and use it in GitHub Desktop.
Save arichardson/2d8c45d03c2c56bdc4c0c9d4f5b51932 to your computer and use it in GitHub Desktop.
class QReadWriteLockPrivate;
typedef __uintcap_t quintptr;
namespace {
enum {
StateMask = 0x3,
StateLockedForRead = 0x1,
StateLockedForWrite = 0x2,
};
const auto dummyLockedForRead = reinterpret_cast<QReadWriteLockPrivate *>(quintptr(StateLockedForRead));
const auto dummyLockedForWrite = reinterpret_cast<QReadWriteLockPrivate *>(quintptr(StateLockedForWrite));
}
bool testAndSetAcquire(void* expected, void* newValue);
void lockSlowPath();
void lock() {
// This previously stored a $ddc derived value instead of a null-derived one
if (testAndSetAcquire(nullptr, dummyLockedForRead))
return;
lockSlowPath();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment