Skip to content

Commit d743384

Browse files
authored
Merge pull request #27 from zeitlinger/stacked/delta-spin-wait
Yield collect-thread spin loops to unblock preempted recorders
2 parents 88a0a79 + 0a9fc7a commit d743384

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DeltaSynchronousMetricStorage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,11 @@ boolean isLockedForCollect() {
291291
}
292292

293293
/** Locks new-series creation and waits for any in-flight new-series operations to complete. */
294+
@SuppressWarnings("ThreadPriorityCheck")
294295
void lockForCollectAndAwait() {
295296
int s = newSeriesGate.addAndGet(1);
296297
while (s != 1) {
298+
Thread.yield();
297299
s = newSeriesGate.get();
298300
}
299301
}
@@ -350,8 +352,11 @@ void lockForCollect() {
350352
}
351353

352354
/** Waits for all in-flight recorders to finish, then clears the collection lock. */
355+
@SuppressWarnings("ThreadPriorityCheck")
353356
void awaitRecordersAndUnlock() {
354-
while (state.get() > 1) {}
357+
while (state.get() > 1) {
358+
Thread.yield();
359+
}
355360
state.addAndGet(-1);
356361
}
357362
}

0 commit comments

Comments
 (0)