use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
the class CaptureCollector method failAll.
/**
* Called to alert the {@link CaptureCollector} all pending captures have failed.
*/
public void failAll() {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h;
while ((h = mActiveRequests.pollFirst()) != null) {
h.setPreviewFailed();
h.setJpegFailed();
}
mPreviewCaptureQueue.clear();
mPreviewProduceQueue.clear();
mJpegCaptureQueue.clear();
mJpegProduceQueue.clear();
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
the class CaptureCollector method previewCaptured.
/**
* Called to alert the {@link CaptureCollector} that the preview capture has begun.
*
* @param timestamp the time of the preview capture.
* @return a pair containing the {@link RequestHolder} and the timestamp of the capture.
*/
public Pair<RequestHolder, Long> previewCaptured(long timestamp) {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mPreviewCaptureQueue.poll();
if (h == null) {
if (DEBUG) {
Log.d(TAG, "previewCaptured called with no preview request on queue!");
}
return null;
}
h.setPreviewTimestamp(timestamp);
return new Pair<>(h.mRequest, h.mTimestamp);
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
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 canal by alibaba.
the class MemoryEventStoreWithBuffer method cleanUntil.
public void cleanUntil(Position position) throws CanalStoreException {
final ReentrantLock lock = this.lock;
lock.lock();
try {
long sequence = ackSequence.get();
long maxSequence = getSequence.get();
boolean hasMatch = false;
long memsize = 0;
for (long next = sequence + 1; next <= maxSequence; next++) {
Event event = entries[getIndex(next)];
memsize += calculateSize(event);
boolean match = CanalEventUtils.checkPosition(event, (LogPosition) position);
if (match) {
// 找到对应的position,更新ack seq
hasMatch = true;
if (batchMode.isMemSize()) {
ackMemSize.addAndGet(memsize);
// 尝试清空buffer中的内存,将ack之前的内存全部释放掉
for (long index = sequence + 1; index < next; index++) {
// 设置为null
entries[getIndex(index)] = null;
}
}
if (ackSequence.compareAndSet(sequence, next)) {
// 避免并发ack
notFull.signal();
return;
}
}
}
if (!hasMatch) {
// 找不到对应需要ack的position
throw new CanalStoreException("no match ack position" + position.toString());
}
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project intellij-community by JetBrains.
the class ConcurrencyUtil method awaitQuiescence.
/**
* Awaits for all tasks in the {@code executor} to finish for the specified {@code timeout}
*/
@TestOnly
public static void awaitQuiescence(@NotNull ThreadPoolExecutor executor, long timeout, @NotNull TimeUnit unit) {
// no need for zombies in tests
executor.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
// interrupt idle workers
executor.setCorePoolSize(0);
ReentrantLock mainLock = ReflectionUtil.getField(executor.getClass(), executor, ReentrantLock.class, "mainLock");
Set workers;
mainLock.lock();
try {
HashSet workersField = ReflectionUtil.getField(executor.getClass(), executor, HashSet.class, "workers");
// to be able to iterate thread-safely outside the lock
workers = new HashSet(workersField);
} finally {
mainLock.unlock();
}
for (Object worker : workers) {
Thread thread = ReflectionUtil.getField(worker.getClass(), worker, Thread.class, "thread");
try {
thread.join(unit.toMillis(timeout));
} catch (InterruptedException e) {
String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
for (final StackTraceElement stackTraceElement : thread.getStackTrace()) {
trace += " at " + stackTraceElement + "\n";
}
trace += "---\n";
System.err.println("Executor " + executor + " is still active after " + unit.toSeconds(timeout) + " seconds://///\n" + "Thread " + thread + " dump:\n" + trace + "all thread dump:\n" + ThreadDumper.dumpThreadsToString() + "\n/////");
break;
}
}
}
Aggregations