📄 sharedlock.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Core License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: SharedLock.java,v 1.4 2000/10/28 16:55:17 daniela Exp $package org.ozoneDB.core;import java.io.*;import org.ozoneDB.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.util.*;/** * This class implements a non-exclusive lock policy. Multiple transactions may * hold this lock. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.4 $Date: 2000/10/28 16:55:17 $ */public final class SharedLock extends AbstractLock { protected final static long serialVersionUID = 1; protected final static byte subSerialVersionUID = 1; private int level = LEVEL_NONE; private transient int prevLevel = LEVEL_NONE; /** * All transactions that hold this lock. Holds TransactionIDs. */ public DxSet lockers; public SharedLock() { reset(); } public synchronized void reset() { level = prevLevel = LEVEL_NONE; lockers = new DxHashSet( 8 ); } public synchronized int tryAcquire( Transaction ta, int newLevel ) { if (ta.env.logWriter.hasTarget( LogWriter.DEBUG3 )) { ta.env.logWriter.newEntry( this, "tryAcquire(): current:" + level + " new:" + newLevel, LogWriter.DEBUG3 ); } int prevLevel = level( ta ); lockers.add( ta.taID() ); if (!lockers.contains( ta.taID() )) { throw new RuntimeException( "tryAcquire(): unable to add ta to lockers." ); //ta.env.logWriter.newEntry (this, "tryAcquire(): unable to add ta to lockers.", LogWriter.WARN); } level = newLevel > level ? newLevel : level; return prevLevel; } public synchronized void release( Transaction ta ) { if (ta.env.logWriter.hasTarget( LogWriter.DEBUG3 )) { ta.env.logWriter.newEntry( this, "release()", LogWriter.DEBUG3 ); } if (!lockers.remove( ta.taID )) { throw new RuntimeException( "release(): transaction does not hold the lock." ); } if (lockers.isEmpty()) { level = LEVEL_NONE; } ta.env.logWriter.newEntry( this, "release(): count=" + lockers.count() + ", level=" + level, LogWriter.DEBUG2 ); } public boolean isAcquiredBy( Transaction ta ) { return lockers != null ? lockers.contains( ta.taID() ) : false; } public DxCollection lockerIDs() { return lockers != null ? lockers : new DxHashSet(); } public int level( Transaction ta ) { if (ta != null) { return isAcquiredBy( ta ) ? level : LEVEL_NONE; } else { return level; } } public int previousLevel() { return prevLevel; } public boolean hasChanged() { return level > prevLevel; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -