Skip to content

Commit

Permalink
Deprecated ThreadHints. (#312)
Browse files Browse the repository at this point in the history
Using Thread.onSpinWait directly.
  • Loading branch information
pveentjer authored Jan 14, 2025
1 parent ebe8c75 commit 2e52a79
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.agrona.concurrent;

import org.agrona.hints.ThreadHints;

import java.util.concurrent.locks.LockSupport;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -201,7 +199,7 @@ public void idle()
break;

case SPINNING:
ThreadHints.onSpinWait();
Thread.onSpinWait();
if (++spins > maxSpins)
{
state = YIELDING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.agrona.concurrent;

import org.agrona.hints.ThreadHints;

/**
* Busy spin strategy targeted at lowest possible latency. This strategy will monopolise a thread to achieve the lowest
* possible latency. Useful for creating bubbles in the execution pipeline of tight busy spin loops with no other logic
Expand Down Expand Up @@ -53,15 +51,15 @@ public void idle(final int workCount)
return;
}

ThreadHints.onSpinWait();
Thread.onSpinWait();
}

/**
* {@inheritDoc}
*/
public void idle()
{
ThreadHints.onSpinWait();
Thread.onSpinWait();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package org.agrona.concurrent;

import org.agrona.concurrent.status.StatusIndicatorReader;
import org.agrona.hints.ThreadHints;

import java.util.concurrent.locks.LockSupport;

/**
* {@link IdleStrategy} which can be controlled by a counter so its mode of operation can be switched between
* doing nothing (NOOP), busy spinning by calling {@link ThreadHints#onSpinWait()}, yielding by calling
* doing nothing (NOOP), busy spinning by calling {@link Thread#onSpinWait()}, yielding by calling
* {@link Thread#yield()}, or sleeping for the minimum period by calling {@link LockSupport#parkNanos(long)} when
* work count is zero, so it idles.
*/
Expand Down Expand Up @@ -101,7 +100,7 @@ public void idle()
break;

case BUSY_SPIN:
ThreadHints.onSpinWait();
Thread.onSpinWait();
break;

case YIELD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.agrona.concurrent;

import org.agrona.UnsafeApi;
import org.agrona.hints.ThreadHints;

import java.util.Collection;
import java.util.function.Consumer;
Expand Down Expand Up @@ -109,7 +108,7 @@ public boolean offer(final E e)
return true;
}

ThreadHints.onSpinWait();
Thread.onSpinWait();
}
}

Expand Down Expand Up @@ -145,7 +144,7 @@ public E poll()
return (E)e;
}

ThreadHints.onSpinWait();
Thread.onSpinWait();
}
}

Expand Down Expand Up @@ -182,7 +181,7 @@ public E peek()
}
}

ThreadHints.onSpinWait();
Thread.onSpinWait();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.agrona.concurrent;

import org.agrona.hints.ThreadHints;

import java.util.concurrent.atomic.AtomicLongFieldUpdater;

abstract class AbstractSnowflakeIdGeneratorPaddingLhs
Expand Down Expand Up @@ -204,7 +202,7 @@ public long maxSequence()

/**
* Generate the next id in sequence. If {@link #maxSequence()} is reached within the same millisecond then this
* implementation will busy spin until the next millisecond using {@link ThreadHints#onSpinWait()} and checking
* implementation will busy spin until the next millisecond using {@link Thread#onSpinWait()} and checking
* for {@link Thread#isInterrupted()}.
*
* @return the next unique id for this node.
Expand Down Expand Up @@ -243,7 +241,7 @@ public long nextId()
throw new IllegalStateException("unexpected thread interrupt");
}

ThreadHints.onSpinWait();
Thread.onSpinWait();
}
}

Expand Down
3 changes: 3 additions & 0 deletions agrona/src/main/java/org/agrona/hints/ThreadHints.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import org.agrona.SystemUtil;

/**
* This class is deprecated. Use {@link Thread#onSpinWait()} directly.
* <p>
* This class captures possible hints that may be used by some
* runtimes to improve code performance. It is intended to capture hinting
* behaviours that are implemented in or anticipated to be spec'ed under the
* {@link java.lang.Thread} class in some Java SE versions, but missing in prior
* versions.
*/
@Deprecated
public final class ThreadHints
{
/**
Expand Down
31 changes: 0 additions & 31 deletions agrona/src/test/java/org/agrona/hints/ThreadHintsTest.java

This file was deleted.

0 comments on commit 2e52a79

Please sign in to comment.