Skip to content

Commit

Permalink
#11932 simplify queue handling
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban authored and olamy committed Jun 26, 2024
1 parent 8f0f4a1 commit 8b4078d
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.EventListener;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
Expand All @@ -39,7 +40,6 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.AutoLock;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy;
Expand Down Expand Up @@ -344,26 +344,19 @@ public Runnable produce()

private class Flusher extends IteratingCallback
{
private final AutoLock lock = new AutoLock();
private final ArrayDeque<Entry> queue = new ArrayDeque<>();
private final Queue<Entry> queue = new ConcurrentLinkedQueue<>();
private Entry entry;

public void offer(Callback callback, SocketAddress address, ByteBuffer[] buffers)
{
try (AutoLock l = lock.lock())
{
queue.offer(new Entry(callback, address, buffers));
}
queue.offer(new Entry(callback, address, buffers));
iterate();
}

@Override
protected Action process()
{
try (AutoLock l = lock.lock())
{
entry = queue.poll();
}
entry = queue.poll();
if (entry == null)
return Action.IDLE;

Expand Down

0 comments on commit 8b4078d

Please sign in to comment.