From 7fc50f10c33d29772d57d8c0af354eeb4eccf3ee Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 15 Oct 2007 00:08:57 +0000 Subject: Minor lock fixes and optimizations. --- .../amazon/carbonado/spi/TransactionManager.java | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java index e8cc637..355af7c 100644 --- a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java @@ -451,12 +451,18 @@ public abstract class TransactionManager { } public void setDesiredLockTimeout(int timeout, TimeUnit unit) { - if (timeout < 0) { - mDesiredLockTimeout = 0; - mTimeoutUnit = null; - } else { - mDesiredLockTimeout = timeout; - mTimeoutUnit = unit; + TransactionManager txnMgr = mTxnMgr; + txnMgr.mLock.lock(); + try { + if (timeout < 0) { + mDesiredLockTimeout = 0; + mTimeoutUnit = null; + } else { + mDesiredLockTimeout = timeout; + mTimeoutUnit = unit; + } + } finally { + txnMgr.mLock.unlock(); } } @@ -464,6 +470,7 @@ public abstract class TransactionManager { return mLevel; } + // Caller must hold mLock. void register(Cursor cursor) { if (mCursorList == null) { mCursorList = new CursorList(); @@ -471,30 +478,28 @@ public abstract class TransactionManager { mCursorList.register(cursor, null); } + // Caller must hold mLock. void unregister(Cursor cursor) { if (mCursorList != null) { mCursorList.unregister(cursor); } } + // Caller must hold mLock. Txn getTxn() throws Exception { - TransactionManager txnMgr = mTxnMgr; - txnMgr.mLock.lock(); - try { - if (mTxn == null) { - Txn parent = (mParent == null || mTop) ? null : mParent.getTxn(); - if (mTimeoutUnit == null) { - mTxn = txnMgr.createTxn(parent, mLevel); - } else { - mTxn = txnMgr.createTxn(parent, mLevel, mDesiredLockTimeout, mTimeoutUnit); - } + if (mTxn == null) { + TransactionManager txnMgr = mTxnMgr; + Txn parent = (mParent == null || mTop) ? null : mParent.getTxn(); + if (mTimeoutUnit == null) { + mTxn = txnMgr.createTxn(parent, mLevel); + } else { + mTxn = txnMgr.createTxn(parent, mLevel, mDesiredLockTimeout, mTimeoutUnit); } - return mTxn; - } finally { - txnMgr.mLock.unlock(); } + return mTxn; } + // Caller must hold mLock. private void closeCursors() throws PersistException { if (mCursorList != null) { mCursorList.closeCursors(); -- cgit v1.2.3