Skip to content

Commit 90d91a1

Browse files
committed
Standard code formatting
1 parent 7123db9 commit 90d91a1

27 files changed

Lines changed: 107 additions & 133 deletions

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ Thread Affinity
22
=============
33
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity)
44

5-
65
Lets you bind a thread to a given core, this can improve performance (this library works best on linux).
76

8-
97
OpenHFT Java Thread Affinity library
108

119
See [affinity/src/test/java](https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java)
@@ -37,15 +35,12 @@ for the artifacts `jna` and `jna-platform` in the project's `pom` file.
3735

3836
### Installing JNA on Ubuntu
3937

40-
4138
sudo apt-get install libjna-java
4239

43-
4440
### Installing JNA on CentOS
4541

4642
sudo yum install jna
4743

48-
4944
## How does CPU allocation work?
5045
The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket.
5146

@@ -57,7 +52,6 @@ To control which CPUs a process can use, add -Daffinity.reserved={cpu-mask-in-he
5752

5853
Note: the CPU 0 is reserved for the Operating System, it has to run somewhere.
5954

60-
6155
## References
6256

6357
https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started
@@ -66,7 +60,6 @@ https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/How-it-works
6660

6761
http://vanillajava.blogspot.co.uk/2013/07/micro-jitter-busy-waiting-and-binding.html
6862

69-
7063
## isolcpus
7164

7265
Java-Thread-Affinity requires that you first isolate some CPU's.
@@ -77,8 +70,7 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system,
7770

7871
isolcpus=1,3
7972

80-
81-
## Acquiring a CPU lock for a thread
73+
## Acquiring a CPU lock for a thread
8274
You can acquire a lock for a CPU in the following matter
8375

8476
In Java 6
@@ -192,5 +184,3 @@ AffinityLock.setAffinity (1L << n);
192184

193185
where n is the cpu you want to run the thread on.
194186

195-
196-

affinity-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<properties>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3939
</properties>
40-
40+
4141
<dependencyManagement>
4242
<dependencies>
4343
<dependency>

affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,45 @@ public class OSGiBundleTest extends net.openhft.affinity.osgi.OSGiTestBase {
3939
@Configuration
4040
public Option[] config() {
4141
return options(
42-
systemProperty("org.osgi.framework.storage.clean").value("true"),
43-
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
44-
mavenBundleAsInProject("org.slf4j","slf4j-api"),
45-
mavenBundleAsInProject("org.slf4j","slf4j-simple").noStart(),
46-
mavenBundleAsInProject("net.openhft","affinity"),
47-
workspaceBundle("affinity-test"),
48-
junitBundles(),
49-
systemPackage("sun.misc"),
50-
systemPackage("sun.nio.ch"),
51-
systemPackage("com.sun.jna"),
52-
systemPackage("com.sun.jna.ptr"),
53-
cleanCaches()
42+
systemProperty("org.osgi.framework.storage.clean").value("true"),
43+
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
44+
mavenBundleAsInProject("org.slf4j", "slf4j-api"),
45+
mavenBundleAsInProject("org.slf4j", "slf4j-simple").noStart(),
46+
mavenBundleAsInProject("net.openhft", "affinity"),
47+
workspaceBundle("affinity-test"),
48+
junitBundles(),
49+
systemPackage("sun.misc"),
50+
systemPackage("sun.nio.ch"),
51+
systemPackage("com.sun.jna"),
52+
systemPackage("com.sun.jna.ptr"),
53+
cleanCaches()
5454
);
5555
}
5656

5757
@Test
5858
public void checkInject() {
5959
assertNotNull(context);
6060
}
61-
61+
6262
@Test
6363
public void checkBundleState() {
6464
final Bundle bundle = findBundle(context, "net.openhft.affinity");
6565
assertNotNull(bundle);
66-
assertEquals(bundle.getState(),Bundle.ACTIVE);
66+
assertEquals(bundle.getState(), Bundle.ACTIVE);
6767
}
68-
68+
6969
@Test
7070
public void checkBundleExports() {
7171
final Bundle bundle = findBundle(context, "net.openhft.affinity");
7272
assertNotNull(bundle);
73-
73+
7474
final String exports = bundle.getHeaders().get("Export-Package");
7575
final String[] packages = exports.split(",");
76-
76+
7777
assertTrue(packages.length >= 2);
78-
assertTrue(packages[0].startsWith("net.openhft.affinity;")
78+
assertTrue(packages[0].startsWith("net.openhft.affinity;")
7979
|| packages[0].startsWith("net.openhft.affinity.impl;"));
80-
assertTrue(packages[1].startsWith("net.openhft.affinity;")
80+
assertTrue(packages[1].startsWith("net.openhft.affinity;")
8181
|| packages[1].startsWith("net.openhft.affinity.impl;"));
8282
}
8383
}

affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@
2626
import java.io.File;
2727

2828
public class OSGiTestBase {
29-
29+
3030
public static Option workspaceBundle(String projectName) {
3131
String baseDir = System.getProperty("main.basedir");
3232
String bundleDir = null;
3333

34-
bundleDir = String.format("%s/%s/target/classes",baseDir,projectName);
35-
if(new File(bundleDir).exists()) {
34+
bundleDir = String.format("%s/%s/target/classes", baseDir, projectName);
35+
if (new File(bundleDir).exists()) {
3636
return CoreOptions.bundle(String.format("reference:file:%s", bundleDir));
3737
}
3838

39-
bundleDir = String.format("%s/../%s/target/classes",baseDir,projectName);
40-
if(new File(bundleDir).exists()) {
39+
bundleDir = String.format("%s/../%s/target/classes", baseDir, projectName);
40+
if (new File(bundleDir).exists()) {
4141
return CoreOptions.bundle(String.format("reference:file:%s", bundleDir));
4242
}
4343

4444
return null;
4545
}
46-
47-
public static MavenArtifactProvisionOption mavenBundleAsInProject(final String groupId,final String artifactId) {
46+
47+
public static MavenArtifactProvisionOption mavenBundleAsInProject(final String groupId, final String artifactId) {
4848
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
4949
}
50-
50+
5151
public static Bundle findBundle(BundleContext context, String symbolicName) {
5252
Bundle[] bundles = context.getBundles();
5353
for (Bundle bundle : bundles) {
@@ -57,7 +57,7 @@ public static Bundle findBundle(BundleContext context, String symbolicName) {
5757
}
5858
}
5959
}
60-
60+
6161
return null;
6262
}
6363
}

affinity/pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
~ limitations under the License.
1616
-->
1717

18-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1920

2021
<parent>
2122
<groupId>net.openhft</groupId>
2223
<artifactId>java-parent-pom</artifactId>
2324
<version>1.1.16</version>
24-
<relativePath />
25+
<relativePath/>
2526
</parent>
2627

2728
<modelVersion>4.0.0</modelVersion>
@@ -112,9 +113,9 @@
112113
</goals>
113114
<configuration>
114115
<target>
115-
<property name="makefile" value="${project.basedir}/${native.source.dir}/Makefile" />
116+
<property name="makefile" value="${project.basedir}/${native.source.dir}/Makefile"/>
116117
<!-- make it executable -->
117-
<chmod file="${makefile}" perm="u+x" />
118+
<chmod file="${makefile}" perm="u+x"/>
118119
</target>
119120
</configuration>
120121
</execution>
@@ -179,7 +180,7 @@
179180
<artifactId>maven-bundle-plugin</artifactId>
180181
<extensions>true</extensions>
181182
<configuration>
182-
<instructions>
183+
<instructions>
183184
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
184185
<Bundle-Name>OpenHFT :: ${project.artifactId}</Bundle-Name>
185186
<Bundle-Version>${project.version}</Bundle-Version>

affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,3 @@ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA
103103
return (jint) sched_getcpu();
104104
}
105105

106-
107-

affinity/src/main/java/java/lang/ThreadLifecycleListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ public interface ThreadLifecycleListener {
2424

2525
/**
2626
* The specified thread is about to be started.
27+
*
2728
* @param t the thread which is being started
2829
*/
2930
void started(Thread t);
3031

3132
/**
3233
* The specified thread failed to start.
34+
*
3335
* @param t the thread that had a failed start
3436
*/
3537
void startFailed(Thread t);
3638

3739
/**
3840
* The specified thread has been terminated.
41+
*
3942
* @param t the thread that has been terminated
4043
*/
4144
void terminated(Thread t);

affinity/src/main/java/net/openhft/affinity/Affinity.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public enum Affinity {
4040
private static final IAffinity AFFINITY_IMPL;
4141
private static Boolean JNAAvailable;
4242

43-
4443
static {
4544
String osName = System.getProperty("os.name");
4645
if (osName.contains("Win") && isWindowsJNAAffinityUsable()) {
@@ -156,16 +155,16 @@ public static BitSet getAffinity() {
156155
return AFFINITY_IMPL.getAffinity();
157156
}
158157

159-
public static void setAffinity(final BitSet affinity) {
160-
AFFINITY_IMPL.setAffinity(affinity);
161-
}
162-
163158
public static void setAffinity(int cpu) {
164159
BitSet affinity = new BitSet(Runtime.getRuntime().availableProcessors());
165160
affinity.set(cpu);
166161
setAffinity(affinity);
167162
}
168163

164+
public static void setAffinity(final BitSet affinity) {
165+
AFFINITY_IMPL.setAffinity(affinity);
166+
}
167+
169168
public static int getCpu() {
170169
return AFFINITY_IMPL.getCpu();
171170
}

affinity/src/main/java/net/openhft/affinity/AffinityLock.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public class AffinityLock implements Closeable {
4444

4545
public static final BitSet BASE_AFFINITY;
4646
public static final BitSet RESERVED_AFFINITY;
47+
static final int ANY_CPU = -1;
4748
private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLock.class);
4849
private static final LockInventory LOCK_INVENTORY;
49-
static final int ANY_CPU = -1;
5050

5151
static {
5252
int processors = Runtime.getRuntime().availableProcessors();
@@ -166,7 +166,6 @@ public static AffinityLock acquireLock(boolean bind) {
166166
return acquireLock(bind, ANY_CPU, AffinityStrategies.ANY);
167167
}
168168

169-
170169
/**
171170
* Assign a cpu which can be bound to the current thread or another thread. <p> This can be used
172171
* for defining your thread layout centrally and passing the handle via dependency injection.
@@ -178,7 +177,6 @@ public static AffinityLock acquireLock(int cpuId) {
178177
return acquireLock(true, cpuId, AffinityStrategies.ANY);
179178
}
180179

181-
182180
/**
183181
* Assign a core(and all its cpus) which can be bound to the current thread or another thread.
184182
* <p> This can be used for defining your thread layout centrally and passing the handle via

affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.jetbrains.annotations.Nullable;
2222

2323
import java.util.concurrent.ThreadFactory;
24-
import java.util.concurrent.atomic.AtomicReference;
2524

2625
/**
2726
* This is a ThreadFactory which assigns threads based the strategies provided.

0 commit comments

Comments
 (0)