@@ -57,6 +57,7 @@ void reset() {
5757 reset = true ;
5858 }
5959
60+ @ SuppressWarnings ("ThreadPriorityCheck" )
6061 <T extends DataPointSnapshot > T run (
6162 Function <Long , Boolean > complete ,
6263 Supplier <T > createResult ,
@@ -70,24 +71,26 @@ <T extends DataPointSnapshot> T run(
7071 // Signal that the buffer is active.
7172 Long expectedCount = observationCount .getAndAdd (bufferActiveBit );
7273
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 ();
8081
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+ }
9091
92+ appendLock .lock ();
93+ try {
9194 while (bufferPos < expectedBufferSize ) {
9295 // Wait until all in-flight threads have added their observations to the buffer.
9396 bufferFilled .await ();
0 commit comments