示例#1
0
 private void writeTracker(Block block) {
   synchronized (this) {
     checkUpdate(Write);
     Long id = block.getId();
     add(Write, id);
     if (!activeWriteBlocks.contains(id)) error(Write, id + " is not an active write block");
   }
 }
示例#2
0
  @Override
  public void release(Block block) {
    synchronized (this) {
      checkReadOrIter(Release);
      Long id = block.getId();
      add(Release, id);

      if (!activeReadBlocks.contains(id)
          && !activeIterBlocks.contains(id)
          && !activeWriteBlocks.contains(id)) error(Release, id + " is not an active block");

      // May have been promoted.
      if (activeWriteBlocks.contains(id)) activeWriteBlocks.remove(id);
      else activeReadBlocks.remove(block.getId());

      activeIterBlocks.remove(block.getId());
    }
    blockMgr.release(block);
  }
示例#3
0
 @Override
 public void free(Block block) {
   synchronized (this) {
     checkUpdate(Free);
     Long id = block.getId();
     add(Free, id);
     if (activeReadBlocks.contains(id)) error(Free, id + " is a read block");
     else if (!activeWriteBlocks.contains(id)) error(Free, id + " is not a write block");
     activeWriteBlocks.remove(id);
   }
   blockMgr.free(block);
 }
示例#4
0
 @Override
 public Block allocate(int blockSize) {
   Block block;
   synchronized (this) {
     checkUpdate(Alloc);
     block = blockMgr.allocate(blockSize);
     Long id = block.getId();
     activeWriteBlocks.add(id);
     add(Alloc, id);
   }
   return block;
 }
示例#5
0
  @Override
  public Block promote(Block block) {
    synchronized (this) {
      checkUpdate(Promote);
      Long id = block.getId();
      add(Promote, id);

      if (!activeWriteBlocks.contains(id) && !activeReadBlocks.contains(id))
        error(Promote, id + " is not an active block");

      if (activeReadBlocks.contains(id))
        // Remove one read count
        // Really, do this if obtained via "getRead" and not "getWrite"
        activeReadBlocks.remove(id);

      // Double promotion results in only one entry.
      if (!activeWriteBlocks.contains(id)) activeWriteBlocks.add(id);
    }
    return blockMgr.promote(block);
  }