package tachyon.worker.block;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * A ReadWrite Lock to guard one block. There should be only one lock per block.
 */
public class BlockLock implements ReadWriteLock {
  public enum BlockLockType {
    READ,  // A read lock
    WRITE,  // A write lock
  }

  private final ReentrantReadWriteLock mLock;
  /** The block Id this lock guards **/
  private final long mBlockId;


  public BlockLock(long blockId) {
    mBlockId = blockId;
    mLock = new ReentrantReadWriteLock();
  }

  public long getBlockId() {
    return mBlockId;
  }

  @Override
  public Lock readLock() {
    return mLock.readLock();
  }

  @Override
  public Lock writeLock() {
    return mLock.writeLock();
  }
}

@@ -28,55 +28,8 @@
 k;%0A%0A
-import java.util.concurrent.atomic.AtomicLong;%0A
 impo
@@ -349,16 +349,19 @@
     READ
+(0)
 ,  // A 
@@ -379,17 +379,20 @@
    WRITE
-,
+(1);
   // A w
@@ -400,16 +400,163 @@
 ite lock
+%0A%0A    private final int mValue;%0A%0A    BlockLockType(int value) %7B%0A      mValue = value;%0A    %7D%0A%0A    public int getValue() %7B%0A      return mValue;%0A    %7D
 %0A  %7D%0A%0A  

Make BlockLockType convertible from and to int