Skip to content

Commit

Permalink
As mentioned by issue LMAX-Exchange#306 - Thread::onSpinWait should g…
Browse files Browse the repository at this point in the history
…et called when we busy spin in SleepingWaitStrategy; But also all of the other wait strategies
  • Loading branch information
Palmr committed Oct 18, 2020
1 parent c1ea0d4 commit 3345200
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lmax.disruptor;

import com.lmax.disruptor.util.ThreadHints;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -52,6 +54,7 @@ public long waitFor(
while ((availableSequence = dependentSequence.get()) < sequence)
{
barrier.checkAlert();
ThreadHints.onSpinWait();
}

return availableSequence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.lmax.disruptor;

import com.lmax.disruptor.util.ThreadHints;

import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -130,6 +132,10 @@ else if (timeDelta > spinTimeoutNanos)
}
counter = SPIN_TRIES;
}
else
{
ThreadHints.onSpinWait();
}
}
while (true);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/lmax/disruptor/SleepingWaitStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.lmax.disruptor;

import com.lmax.disruptor.util.ThreadHints;

import java.util.concurrent.locks.LockSupport;

/**
Expand Down Expand Up @@ -81,6 +83,7 @@ private int applyWaitMethod(final SequenceBarrier barrier, int counter)
if (counter > 100)
{
--counter;
ThreadHints.onSpinWait();
}
else if (counter > 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lmax.disruptor;

import com.lmax.disruptor.util.ThreadHints;

import java.util.concurrent.TimeUnit;

import static com.lmax.disruptor.util.Util.awaitNanos;
Expand Down Expand Up @@ -52,6 +54,7 @@ public long waitFor(
while ((availableSequence = dependentSequence.get()) < sequence)
{
barrier.checkAlert();
ThreadHints.onSpinWait();
}

return availableSequence;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/lmax/disruptor/YieldingWaitStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.lmax.disruptor;


import com.lmax.disruptor.util.ThreadHints;

/**
* Yielding strategy that uses a Thread.yield() for {@link com.lmax.disruptor.EventProcessor}s waiting on a barrier
* after an initially spinning.
Expand Down Expand Up @@ -60,6 +62,7 @@ private int applyWaitMethod(final SequenceBarrier barrier, int counter)
else
{
--counter;
ThreadHints.onSpinWait();
}

return counter;
Expand Down

0 comments on commit 3345200

Please sign in to comment.