public class ControllableIdleStrategy extends Object implements IdleStrategy
IdleStrategy
which can be controlled by a counter so its mode of operation can be switched between
doing nothing (NOOP), busy spinning by calling ThreadHints.onSpinWait()
, yielding by calling
Thread.yield()
, or sleeping for the minimum period by calling LockSupport.parkNanos(long)
when
work count is zero so it idles.Modifier and Type | Field and Description |
---|---|
static int |
BUSY_SPIN |
static int |
NOOP |
static int |
NOT_CONTROLLED |
static int |
PARK |
static int |
YIELD |
Constructor and Description |
---|
ControllableIdleStrategy(StatusIndicatorReader statusIndicator) |
Modifier and Type | Method and Description |
---|---|
void |
idle()
Perform current idle action (e.g.
|
void |
idle(int workCount)
Idle based on current status indication value
|
void |
reset()
Reset the internal state in preparation for entering an idle state again.
|
String |
toString() |
public static final int NOT_CONTROLLED
public static final int NOOP
public static final int BUSY_SPIN
public static final int YIELD
public static final int PARK
public ControllableIdleStrategy(StatusIndicatorReader statusIndicator)
public void idle(int workCount)
idle
in interface IdleStrategy
workCount
- performed in last duty cycle.IdleStrategy.idle(int)
public void idle()
IdleStrategy.reset()
to clear internal state when idle period is over (or before it begins).
Callers are expected to follow this pattern:
while (isRunning)
{
if (!hasWork())
{
idleStrategy.reset();
while (!hasWork())
{
if (!isRunning)
{
return;
}
idleStrategy.idle();
}
}
doWork();
}
idle
in interface IdleStrategy
public void reset()
reset
in interface IdleStrategy
Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.