/** * @param lock Lock address. */ public boolean tryWriteLock(long lock, int tag) { long state = GridUnsafe.getLongVolatile(null, lock); return checkTag(state, tag) && canWriteLock(state) && GridUnsafe.compareAndSwapLong(null, lock, state, updateState(state, -1, 0, 0)); }
/** * Signal that update operation finished. */ public void endUpdate() { Sync<X> sync0 = sync; if (sync0.releaseAfterUpdate()) takeSnapshotAndReplaceSync(sync0); }
/** * @throws Exception If failed. */ @Test public void testQueueSize() throws Exception { stripedExecSvc.execute(1, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); assertEquals(1, stripedExecSvc.queueSize()); }
/** * @throws Exception If failed. */ @Test public void testCompletedTasks() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable()); sleepASec(); assertEquals(2, stripedExecSvc.completedTasks()); }
/** * @throws Exception If failed. */ @Test public void testActiveStripesCount() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); assertEquals(1, stripedExecSvc.activeStripesCount()); }
/** {@inheritDoc} */ @Override public int size() { removeStale(); return store.size(); }
/** {@inheritDoc} */ @Override public int size() { removeStale(); return store.size(); }
/** {@inheritDoc} */ @Override public boolean isEmpty() { removeStale(); return store.isEmpty(); }
/** {@inheritDoc} */ @Override public boolean isEmpty() { removeStale(); return store.isEmpty(); }
/** * @return Consistent snapshot of data. */ public X snapshot() { Sync<X> sync0 = sync; if (sync0.flip()) takeSnapshotAndReplaceSync(sync0); return sync0.get(); }
/** * @param lock Lock to check. * @return {@code True} if write lock is held by any thread for the given offheap RW lock. */ public boolean isWriteLocked(long lock) { return lockCount(GridUnsafe.getLongVolatile(null, lock)) == -1; }
/** * Creates a new instance with given concurrency level. * * @param concurrencyLvl Number of internal read locks. */ public StripedCompositeReadWriteLock(int concurrencyLvl) { locks = new ReadLock[concurrencyLvl]; for (int i = 0; i < concurrencyLvl; i++) locks[i] = new ReadLock(); writeLock = new WriteLock(); }
/** * @param lock Lock to check. * @return {@code True} if at least one read lock is held by any thread for the given offheap RW lock. */ public boolean isReadLocked(long lock) { return lockCount(GridUnsafe.getLongVolatile(null, lock)) > 0; }