PageDb() { mCommitLock = new CommitLock(); }
@Override public boolean compactionStart(long targetPageCount) throws IOException { mCommitLock.acquireExclusive(); try { return mPageManager.compactionStart(targetPageCount); } catch (Throwable e) { throw closeOnFailure(e); } finally { mCommitLock.releaseExclusive(); } }
/** * Acquire shared lock. */ @Override public void lock() { acquireShared(); }
mRemoveLock.unlock(); CommitLock.Shared shared = commitLock.acquireShared(); try { while (mCompacting) { mRecycleFreeList.append(pageId); if (commitLock.hasQueuedThreads()) { shared.release(); shared = commitLock.acquireShared();
/** * Safely acquire shared commit lock while node latch is held exclusively. Latch might need * to be released and relatched in order to obtain shared commit lock without deadlocking. * As a result, the caller must not rely on any existing node reference. It must be * accessed again from the leaf frame instance. * * @param leaf leaf frame, latched exclusively, which might be released and relatched * @return held commitLock */ final CommitLock.Shared commitLock(final CursorFrame leaf) { CommitLock commitLock = mTree.mDatabase.commitLock(); CommitLock.Shared shared = commitLock.tryAcquireShared(); if (shared == null) { leaf.mNode.releaseExclusive(); shared = commitLock.acquireShared(); leaf.acquireExclusive(); } return shared; }
/** * Release shared lock. */ @Override public void unlock() { releaseShared(); mShared.get().count--; }
/** * Acquire shared lock. */ @Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { return tryAcquireShared(time, unit) != null; }
void releaseShared() { mSharedRelease.increment(); Thread t = mExclusiveThread; if (t != null && !hasSharedLockers()) { LockSupport.unpark(t); } }
mCommitLock.releaseExclusive();
void acquireExclusive() throws InterruptedIOException { // If full exclusive lock cannot be immediately obtained, it's due to a shared lock // being held for a long time. While waiting for the exclusive lock, all other shared // requests are queued. By waiting a timed amount and giving up, the exclusive lock // request is effectively de-prioritized. For each retry, the timeout is doubled, to // ensure that the exclusive request is not starved. long nanosTimeout = 1000; // 1 microsecond while (!finishAcquireExclusive(nanosTimeout)) { nanosTimeout <<= 1; } }
/** * Acquire shared lock. */ @Override public void lockInterruptibly() throws InterruptedException { acquireSharedInterruptibly(); }
mRemoveLock.unlock(); CommitLock.Shared shared = commitLock.acquireShared(); try { while (mCompacting) { mRecycleFreeList.append(pageId); if (commitLock.hasQueuedThreads()) { shared.release(); shared = commitLock.acquireShared();
/** * Safely acquire shared commit lock while node latch is held exclusively. Latch might need * to be released and relatched in order to obtain shared commit lock without deadlocking. * As a result, the caller must not rely on any existing node reference. It must be * accessed again from the leaf frame instance. * * @param leaf leaf frame, latched exclusively, which might be released and relatched * @return held commitLock */ final CommitLock.Shared commitLock(final _CursorFrame leaf) { CommitLock commitLock = mTree.mDatabase.commitLock(); CommitLock.Shared shared = commitLock.tryAcquireShared(); if (shared == null) { leaf.mNode.releaseExclusive(); shared = commitLock.acquireShared(); leaf.acquireExclusive(); } return shared; }
/** * Release shared lock. */ @Override public void unlock() { releaseShared(); mShared.get().count--; }
/** * Acquire shared lock. */ @Override public boolean tryLock() { return tryAcquireShared() != null; }
void releaseShared() { mSharedRelease.increment(); Thread t = mExclusiveThread; if (t != null && !hasSharedLockers()) { LockSupport.unpark(t); } }
mCommitLock.releaseExclusive();
void acquireExclusive() throws InterruptedIOException { // If full exclusive lock cannot be immediately obtained, it's due to a shared lock // being held for a long time. While waiting for the exclusive lock, all other shared // requests are queued. By waiting a timed amount and giving up, the exclusive lock // request is effectively de-prioritized. For each retry, the timeout is doubled, to // ensure that the exclusive request is not starved. long nanosTimeout = 1000; // 1 microsecond while (!finishAcquireExclusive(nanosTimeout)) { nanosTimeout <<= 1; } }
/** * Acquire shared lock. */ @Override public void lockInterruptibly() throws InterruptedException { acquireSharedInterruptibly(); }
@Override public boolean compactionStart(long targetPageCount) throws IOException { mCommitLock.acquireExclusive(); try { return mPageManager.compactionStart(targetPageCount); } catch (Throwable e) { throw closeOnFailure(e); } finally { mCommitLock.releaseExclusive(); } }