@@ -57,6 +57,7 @@ void reset() {
57
57
reset = true ;
58
58
}
59
59
60
+ @ SuppressWarnings ("ThreadPriorityCheck" )
60
61
<T extends DataPointSnapshot > T run (
61
62
Function <Long , Boolean > complete ,
62
63
Supplier <T > createResult ,
@@ -70,24 +71,26 @@ <T extends DataPointSnapshot> T run(
70
71
// Signal that the buffer is active.
71
72
Long expectedCount = observationCount .getAndAdd (bufferActiveBit );
72
73
73
- appendLock . lock ();
74
- try {
75
- while (! complete . apply ( expectedCount )) {
76
- // Wait until all in-flight threads have added their observations to the buffer .
77
- bufferFilled . await ();
78
- }
79
- result = createResult .get ();
74
+ while (! complete . apply ( expectedCount )) {
75
+ // Wait until all in-flight threads have added their observations to the histogram
76
+ // we can't use a condition here, because the other thread doesn't have a lock as it's on
77
+ // the fast path .
78
+ Thread . yield ();
79
+ }
80
+ result = createResult .get ();
80
81
81
- // Signal that the buffer is inactive.
82
- int expectedBufferSize ;
83
- if (reset ) {
84
- expectedBufferSize =
85
- (int ) ((observationCount .getAndSet (0 ) & ~bufferActiveBit ) - expectedCount );
86
- reset = false ;
87
- } else {
88
- expectedBufferSize = (int ) (observationCount .addAndGet (bufferActiveBit ) - expectedCount );
89
- }
82
+ // Signal that the buffer is inactive.
83
+ int expectedBufferSize ;
84
+ if (reset ) {
85
+ expectedBufferSize =
86
+ (int ) ((observationCount .getAndSet (0 ) & ~bufferActiveBit ) - expectedCount );
87
+ reset = false ;
88
+ } else {
89
+ expectedBufferSize = (int ) (observationCount .addAndGet (bufferActiveBit ) - expectedCount );
90
+ }
90
91
92
+ appendLock .lock ();
93
+ try {
91
94
while (bufferPos < expectedBufferSize ) {
92
95
// Wait until all in-flight threads have added their observations to the buffer.
93
96
bufferFilled .await ();
0 commit comments