Exemplo n.º 1
0
 @Stage("Locks")
 public void readUnlockAndDecrementCount() {
   switch (localLockState) {
     case UNLOCKED:
       return;
     case READ_LOCKED:
       if (decrementRead() == 0) {
         if (updateZero() && writeZero()) segmentHeader.readUnlock(segmentHeaderAddress);
       }
       return;
     case UPDATE_LOCKED:
       if (decrementUpdate() == 0) {
         if (writeZero()) {
           if (readZero()) {
             segmentHeader.updateUnlock(segmentHeaderAddress);
           } else {
             segmentHeader.downgradeUpdateToReadLock(segmentHeaderAddress);
           }
         }
       }
       return;
     case WRITE_LOCKED:
       if (decrementWrite() == 0) {
         if (!updateZero()) {
           segmentHeader.downgradeWriteToUpdateLock(segmentHeaderAddress);
         } else {
           if (!readZero()) {
             segmentHeader.downgradeWriteToReadLock(segmentHeaderAddress);
           } else {
             segmentHeader.writeUnlock(segmentHeaderAddress);
           }
         }
       }
   }
 }
Exemplo n.º 2
0
  @Stage("Locks")
  private void closeRootLocks() {
    verifyInnermostContext();

    switch (localLockState) {
      case UNLOCKED:
        return;
      case READ_LOCKED:
        segmentHeader.readUnlock(segmentHeaderAddress);
        return;
      case UPDATE_LOCKED:
        segmentHeader.updateUnlock(segmentHeaderAddress);
        return;
      case WRITE_LOCKED:
        segmentHeader.writeUnlock(segmentHeaderAddress);
    }
  }