public class AffinityLock extends Object implements Closeable
| Modifier and Type | Field and Description |
|---|---|
static String |
AFFINITY_RESERVED |
static BitSet |
BASE_AFFINITY |
static int |
PROCESSORS |
static BitSet |
RESERVED_AFFINITY |
| Modifier and Type | Method and Description |
|---|---|
static AffinityLock |
acquireCore()
Assign any free core to this thread.
|
static AffinityLock |
acquireCore(boolean bind)
Assign a core(and all its cpus) which can be bound to the current thread or another thread.
|
static AffinityLock |
acquireLock()
Assign any free cpu to this thread.
|
AffinityLock |
acquireLock(AffinityStrategy... strategies)
Give another affinity lock relative to this one based on a list of strategies.
|
static AffinityLock |
acquireLock(boolean bind)
Assign a cpu which can be bound to the current thread or another thread.
|
static AffinityLock |
acquireLock(int cpuId)
Assign a cpu which can be bound to the current thread or another thread.
|
static AffinityLock |
acquireLock(int[] cpus)
Assign a cpu which can be bound to the current thread or another thread
Caller passes in an explicit set of preferred CPUs
The first available CPU is used, and the lock returned
If all CPUs in the set are unavailable then no lock is obtained
|
static AffinityLock |
acquireLock(String desc)
Use a description to allocate a cpu.
|
static AffinityLock |
acquireLockLastMinus(int n)
Allocate from the end.
|
void |
bind()
Bind the current thread to this reservable lock.
|
void |
bind(boolean wholeCore)
Bind the current thread to this reservable lock.
|
void |
close() |
int |
cpuId() |
static @NotNull CpuLayout |
cpuLayout() |
static void |
cpuLayout(@NotNull CpuLayout cpuLayout)
Set the CPU layout for this machine.
|
static @NotNull String |
dumpLocks() |
protected void |
finalize() |
boolean |
isAllocated() |
boolean |
isBound() |
void |
release()
Release the current AffinityLock which can be discarded.
|
boolean |
resetAffinity() |
AffinityLock |
resetAffinity(boolean resetAffinity) |
String |
toString() |
public static final String AFFINITY_RESERVED
public static final int PROCESSORS
public static final BitSet BASE_AFFINITY
public static final BitSet RESERVED_AFFINITY
public static void cpuLayout(@NotNull
@NotNull CpuLayout cpuLayout)
Changing the layout will have no impact on thread which have already been assigned. It only affects subsequent assignments.
cpuLayout - for this application to use for this machine.@NotNull public static @NotNull CpuLayout cpuLayout()
public static AffinityLock acquireLock()
public static AffinityLock acquireCore()
In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used.
public static AffinityLock acquireLock(boolean bind)
This can be used for defining your thread layout centrally and passing the handle via dependency injection.
bind - if true, bind the current thread, if false, reserve a cpu which can be bound
later.public static AffinityLock acquireLock(int cpuId)
This can be used for defining your thread layout centrally and passing the handle via dependency injection.
cpuId - the CPU id to bind topublic static AffinityLock acquireLock(int[] cpus)
cpus - the array of available CPUs to bind topublic static AffinityLock acquireLockLastMinus(int n)
n - positive number to allocate from.public static AffinityLock acquireLock(String desc)
desc - of which cpu to pickpublic static AffinityLock acquireCore(boolean bind)
This can be used for defining your thread layout centrally and passing the handle via dependency injection.
bind - if true, bind the current thread, if false, reserve a cpu which can be bound
later.@NotNull public static @NotNull String dumpLocks()
public boolean resetAffinity()
public AffinityLock resetAffinity(boolean resetAffinity)
resetAffinity - Whether to reset the affinity, false indicates the thread is about to die anyway.public void bind()
public void bind(boolean wholeCore)
wholeCore - if true, also reserve the whole core.public AffinityLock acquireLock(AffinityStrategy... strategies)
The strategies are evaluated in order to (like a search path) to find the next appropriate thread. If ANY is not the last strategy, a warning is logged and no cpu is assigned (leaving the OS to choose)
strategies - To determine if you want the same/different core/socket.public void release()
public void close()
close in interface Closeableclose in interface AutoCloseableprotected void finalize()
throws Throwable
public int cpuId()
public boolean isAllocated()
public boolean isBound()
Copyright © 2022. All rights reserved.