MCPcopy Create free account
hub / github.com/questdb/questdb / ConcurrentPool

Class ConcurrentPool

core/src/main/java/io/questdb/mp/ConcurrentPool.java:30–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28import java.util.concurrent.atomic.AtomicInteger;
29
30public class ConcurrentPool<T> {
31 @SuppressWarnings("rawtypes")
32 public static final ConcurrentSegmentManipulator POOL_MANIPULATOR = new ConcurrentSegmentManipulator() {
33
34 @Override
35 public Object dequeue(ConcurrentQueueSegment.Slot[] slots, int slotsIndex, Object unused) {
36 var val = slots[slotsIndex].item;
37 slots[slotsIndex].item = null;
38 return val;
39 }
40
41 @Override
42 public void enqueue(Object item, ConcurrentQueueSegment.Slot[] slots, int slotsIndex) {
43 slots[slotsIndex].item = item;
44 }
45 };
46 private final AtomicInteger count = new AtomicInteger(0);
47 private final ConcurrentQueue<T> queue;
48
49 public ConcurrentPool() {
50 //noinspection unchecked
51 this.queue = new ConcurrentQueue<T>(() -> null, POOL_MANIPULATOR);
52 }
53
54 public int capacity() {
55 return queue.capacity();
56 }
57
58 public int count() {
59 return count.get();
60 }
61
62 public T pop() {
63 T val = queue.tryDequeueValue(null);
64 if (val != null) {
65 count.decrementAndGet();
66 }
67 return val;
68 }
69
70 public void push(T item) {
71 queue.enqueue(item);
72 count.incrementAndGet();
73 }
74}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…