12.07.2015 Views

QRL-OpLocks-BiasedLocking

QRL-OpLocks-BiasedLocking

QRL-OpLocks-BiasedLocking

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

int data;}lockword;volatile long defaultlock;}qrltas_lock;void qrltas_initialize(qrltas_lock *L){L->lockword.data = MAKEDWORD(0, NEUTRAL);L->defaultlock = 0;}int qrltas_acquire(qrltas_lock *L, int id){int status = L->lockword.h.status;/* If the lock’s mine, I can reenter by just setting a flag */if (BIASED(id) == status){L->lockword.h.quicklock = 1;if (BIASED(id) == HIGHWORD(L->lockword.data))return 1;L->lockword.h.quicklock = 0; /* I didn’t get the lock, so make sure Idon’t block up the process that did */}if (DEFAULT != status){/* If the lock is unowned, try to claim it */if (NEUTRAL == status){if (CAS(&L->lockword, /* By definition, if we saw */MAKEDWORD(0, NEUTRAL), /* neutral, the lock is unheld */MAKEDWORD(1, BIASED(id)))){/* Biasing the lock counts as an acquisition */return 1;}/* If I didn’t bias the lock to me, someone else just grabbedit. Fall through to the revocation code */status = L->lockword.h.status; /* resample */}/* If someone else owns the lock, revoke them */if (ISBIASED(status)){do{unsigned short biaslock = L->lockword.h.quicklock;if (CAS(&L->lockword,MAKEDWORD(biaslock, status),MAKEDWORD(biaslock, REVOKED))){13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!