Skip to content

Commit 21e0a65

Browse files
committed
test
1 parent 259eeb5 commit 21e0a65

File tree

3 files changed

+3
-42
lines changed

3 files changed

+3
-42
lines changed

utils/queue-utils/src/main/java/datadog/common/queue/MpscArrayQueueVarHandle.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package datadog.common.queue;
22

33
import java.util.Objects;
4-
import java.util.concurrent.locks.LockSupport;
54

65
/**
76
* A Multiple-Producer, Single-Consumer (MPSC) bounded lock-free queue using a circular array and
@@ -43,9 +42,6 @@ public boolean offer(E e) {
4342
long localProducerLimit = producerLimit;
4443
long cachedHead = 0L; // Local cache of head to reduce volatile reads
4544

46-
int spinCycles = 0;
47-
boolean parkOnSpin = (Thread.currentThread().getId() & 1) == 0;
48-
4945
while (true) {
5046
long currentTail = (long) TAIL_HANDLE.getVolatile(this);
5147

@@ -73,16 +69,7 @@ public boolean offer(E e) {
7369
}
7470

7571
// Backoff to reduce contention
76-
if ((spinCycles & 1) == 0) {
77-
Thread.onSpinWait();
78-
} else {
79-
if (parkOnSpin) {
80-
LockSupport.parkNanos(1);
81-
} else {
82-
Thread.yield();
83-
}
84-
}
85-
spinCycles++;
72+
Thread.onSpinWait();
8673
}
8774
}
8875

utils/queue-utils/src/main/java/datadog/common/queue/MpscBlockingConsumerArrayQueueVarHandle.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public final boolean offer(E e) {
6161
long localProducerLimit = producerLimit;
6262
long cachedHead = 0L; // Local cache of head to reduce volatile reads
6363

64-
int spinCycles = 0;
65-
boolean parkOnSpin = (Thread.currentThread().getId() & 1) == 0;
66-
6764
while (true) {
6865
long currentTail = (long) TAIL_HANDLE.getVolatile(this);
6966

@@ -93,21 +90,11 @@ public final boolean offer(E e) {
9390
if (c != null) {
9491
LockSupport.unpark(c);
9592
}
96-
9793
return true;
9894
}
9995

10096
// Backoff to reduce contention
101-
if ((spinCycles & 1) == 0) {
102-
Thread.onSpinWait();
103-
} else {
104-
if (parkOnSpin) {
105-
LockSupport.parkNanos(1);
106-
} else {
107-
Thread.yield();
108-
}
109-
}
110-
spinCycles++;
97+
Thread.onSpinWait();
11198
}
11299
}
113100

utils/queue-utils/src/main/java/datadog/common/queue/SpmcArrayQueueVarHandle.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package datadog.common.queue;
22

33
import java.util.Objects;
4-
import java.util.concurrent.locks.LockSupport;
54

65
/**
76
* A Single-Producer, Multiple-Consumer (SPMC) bounded, lock-free queue based on a circular array.
@@ -58,9 +57,6 @@ public boolean offer(E e) {
5857
public E poll() {
5958
final Object[] localBuffer = this.buffer;
6059

61-
int spinCycles = 0;
62-
boolean parkOnSpin = (Thread.currentThread().getId() & 1) == 0;
63-
6460
while (true) {
6561
long currentHead = (long) HEAD_HANDLE.getVolatile(this);
6662
long limit = consumerLimit; // cached tail
@@ -77,16 +73,7 @@ public E poll() {
7773
// Attempt to claim this slot
7874
if (!HEAD_HANDLE.compareAndSet(this, currentHead, currentHead + 1)) {
7975
// CAS failed. Backoff to reduce contention
80-
if ((spinCycles & 1) == 0) {
81-
Thread.onSpinWait();
82-
} else {
83-
if (parkOnSpin) {
84-
LockSupport.parkNanos(1);
85-
} else {
86-
Thread.yield();
87-
}
88-
}
89-
spinCycles++;
76+
Thread.onSpinWait();
9077
continue;
9178
}
9279

0 commit comments

Comments
 (0)