use of java.util.concurrent.locks.ReentrantLock in project voltdb by VoltDB.
the class ForkJoinTask method clearExceptionalCompletion.
/**
* Removes exception node and clears status.
*/
private void clearExceptionalCompletion() {
int h = System.identityHashCode(this);
final ReentrantLock lock = exceptionTableLock;
lock.lock();
try {
ExceptionNode[] t = exceptionTable;
int i = h & (t.length - 1);
ExceptionNode e = t[i];
ExceptionNode pred = null;
while (e != null) {
ExceptionNode next = e.next;
if (e.get() == this) {
if (pred == null)
t[i] = next;
else
pred.next = next;
break;
}
pred = e;
e = next;
}
expungeStaleExceptions();
status = 0;
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project voltdb by VoltDB.
the class StateMachineSnipits method testLockingExample.
@Test
public void testLockingExample() {
// Create a state machine manager operating in the LOCK_TESTER domain that will run on ZooKeeper0.
// This manager is named manager1 and it expects a single state machine instance.
SynchronizedStatesManager ssm1 = addStateMachineManagerFor(0, "LOCK_TESTER", "manager1", 1);
// Create a state machine manager operating in the LOCK_TESTER domain that will run on ZooKeeper1.
// This manager is named manager2 and it expects a single state machine instance.
SynchronizedStatesManager ssm2 = addStateMachineManagerFor(1, "LOCK_TESTER", "manager2", 1);
// This is a little convoluted, but because StateMachineInstances are a nested class of
// SynchronizedStatesManager we must specify the correct SynchronizedStatesManager in the
// constructor. The second parameter is the state machine name shared by all instances wishing
// to participate in the same shared machine across Manager instances using the same
// domain (LOCK_TESTER).
DistributedLock distributedLock1 = new DistributedLock(ssm1, "lockingStateMachine");
try {
distributedLock1.start();
} catch (InterruptedException e1) {
fail();
}
DistributedLock distributedLock2 = new DistributedLock(ssm2, "lockingStateMachine");
try {
distributedLock2.start();
} catch (InterruptedException e1) {
fail();
}
while (!distributedLock1.isInitialized()) {
Thread.yield();
}
while (!distributedLock2.isInitialized()) {
Thread.yield();
}
distributedLock1.acquireDistriutedLock();
Lock waiterForLock2 = new ReentrantLock();
distributedLock2.acquireDistributedLockAsync(waiterForLock2);
try {
ssm2 = null;
failSite(1);
distributedLock1.releaseDistributedLock();
} catch (Exception e) {
fail();
}
// Create a state machine manager operating in the LOCK_TESTER domain that will run on ZooKeeper0.
// This manager is named manager3 and it expects a single state machine instance.
SynchronizedStatesManager ssm3 = addStateMachineManagerFor(0, "LOCK_TESTER", "manager3", 1);
DistributedLock distributedLock3 = new DistributedLock(ssm3, "lockingStateMachine");
try {
distributedLock3.start();
} catch (InterruptedException e1) {
fail();
}
try {
// release their locks.
while (!distributedLock3.isInitialized()) {
Thread.yield();
}
Lock waiterForLock3 = new ReentrantLock();
distributedLock3.acquireDistributedLockAsync(waiterForLock3);
synchronized (waiterForLock3) {
while (!distributedLock3.m_locked) waiterForLock3.wait();
}
waiterForLock3 = null;
distributedLock3.releaseDistributedLock();
tearDownZK();
} catch (Exception e) {
fail();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by ResurrectionRemix.
the class RenderAction method release.
/**
* Cleans up the scene after an action.
*/
public void release() {
ReentrantLock lock = Bridge.getLock();
// not throw IllegalMonitorStateException.
if (lock.isHeldByCurrentThread()) {
tearDown();
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by ResurrectionRemix.
the class CaptureCollector method failNextJpeg.
/**
* Called to alert the {@link CaptureCollector} that the next pending jpeg capture has failed.
*/
public void failNextJpeg() {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h1 = mJpegCaptureQueue.peek();
CaptureHolder h2 = mJpegProduceQueue.peek();
// Find the request with the lowest frame number.
CaptureHolder h = (h1 == null) ? h2 : ((h2 == null) ? h1 : ((h1.compareTo(h2) <= 0) ? h1 : h2));
if (h != null) {
mJpegCaptureQueue.remove(h);
mJpegProduceQueue.remove(h);
mActiveRequests.remove(h);
h.setJpegFailed();
}
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by ResurrectionRemix.
the class CaptureCollector method waitForEmpty.
/**
* Wait all queued requests to complete.
*
* @param timeout a timeout to use for this call.
* @param unit the units to use for the timeout.
* @return {@code false} if this method timed out.
* @throws InterruptedException if this thread is interrupted.
*/
public boolean waitForEmpty(long timeout, TimeUnit unit) throws InterruptedException {
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.mLock;
lock.lock();
try {
while (mInFlight > 0) {
if (nanos <= 0) {
return false;
}
nanos = mIsEmpty.awaitNanos(nanos);
}
return true;
} finally {
lock.unlock();
}
}
Aggregations