File tree Expand file tree Collapse file tree
src/main/java/com/zaxxer/hikari/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11HikariCP Changes
22
3+ Changes in 7.0.2
4+
5+ * decrease thread yield frequency in ConcurrentBag.unreserve()
6+
37Changes in 7.0.1
48
59 * merged #2346 fix regression with setSchema behavior
Original file line number Diff line number Diff line change 5757 * @param <T> the templated type to store in the bag
5858 * @hidden
5959 */
60+ @ SuppressWarnings ("DuplicatedCode" )
6061public class ConcurrentBag <T extends IConcurrentBagEntry > implements AutoCloseable
6162{
6263 private static final Logger LOGGER = LoggerFactory .getLogger (ConcurrentBag .class );
@@ -318,8 +319,16 @@ public void unreserve(final T bagEntry)
318319 {
319320 if (bagEntry .compareAndSet (STATE_RESERVED , STATE_NOT_IN_USE )) {
320321 // spin until a thread takes it or none are waiting
321- while (waiters .get () > 0 && bagEntry .getState () == STATE_NOT_IN_USE && !handoffQueue .offer (bagEntry )) {
322- Thread .yield ();
322+ for (int i = 1 , waiting = waiters .get (); waiting > 0 ; i ++, waiting = waiters .get ()) {
323+ if (bagEntry .getState () != STATE_NOT_IN_USE || handoffQueue .offer (bagEntry )) {
324+ return ;
325+ }
326+ else if ((i & 0xff ) == 0xff || (waiting > 1 && i % waiting == 0 )) {
327+ parkNanos (MICROSECONDS .toNanos (10 ));
328+ }
329+ else {
330+ Thread .yield ();
331+ }
323332 }
324333 }
325334 else {
You can’t perform that action at this time.
0 commit comments