use of jetbrains.exodus.core.execution.locks.Guard in project xodus by JetBrains.
the class JobProcessorQueueAdapter method queueLowest.
@Override
protected boolean queueLowest(@NotNull Job job) {
if (isFinished())
return false;
if (job.getProcessor() == null) {
job.setProcessor(this);
}
try (Guard ignored = queue.lock()) {
final Pair<Priority, Job> pair = queue.floorPair();
final Priority priority = pair == null ? Priority.highest : pair.getFirst();
if (queue.push(priority, job) != null) {
return false;
}
}
awake.release();
return true;
}
use of jetbrains.exodus.core.execution.locks.Guard in project xodus by JetBrains.
the class JobProcessorQueueAdapter method queueLowestTimed.
@Override
protected boolean queueLowestTimed(@NotNull final Job job) {
if (isFinished()) {
return false;
}
if (job.getProcessor() == null) {
job.setProcessor(this);
}
try (Guard ignored = timeQueue.lock()) {
final Pair<Long, Job> pair = timeQueue.floorPair();
final long priority = pair == null ? Long.MAX_VALUE - System.currentTimeMillis() : pair.getFirst();
if (timeQueue.push(priority, job) != null) {
return false;
}
}
awake.release();
return true;
}
use of jetbrains.exodus.core.execution.locks.Guard in project xodus by JetBrains.
the class PriorityQueue method moveQueue.
// Returns size of the destination (and obviously of the source) queue
public static <P extends Comparable<? super P>, E> int moveQueue(@NotNull final PriorityQueue<P, E> source, @NotNull final PriorityQueue<P, E> dest) {
try (Guard ignored = source.lock()) {
try (Guard ignore = dest.lock()) {
while (true) {
final Pair<P, E> pair = source.peekPair();
if (pair == null)
break;
dest.push(pair.getFirst(), pair.getSecond());
source.pop();
}
return dest.size();
}
}
}
use of jetbrains.exodus.core.execution.locks.Guard in project xodus by JetBrains.
the class StablePriorityQueue method clear.
@Override
public void clear() {
try (Guard ignored = lock()) {
theQueue.clear();
priorities.clear();
size.set(0);
}
}
use of jetbrains.exodus.core.execution.locks.Guard in project xodus by JetBrains.
the class JobProcessorQueueAdapter method pushAt.
@Override
protected Job pushAt(final Job job, final long millis) {
if (isFinished()) {
return null;
}
if (job.getProcessor() == null) {
job.setProcessor(this);
}
Job oldJob;
final Pair<Long, Job> pair;
final long priority = Long.MAX_VALUE - millis;
try (Guard ignored = timeQueue.lock()) {
oldJob = timeQueue.push(priority, job);
pair = timeQueue.peekPair();
}
if (pair != null && pair.getFirst() != priority) {
return oldJob;
}
awake.release();
return oldJob;
}
Aggregations