Skip to content

Commit efddeeb

Browse files
committed
Port to windows
1 parent 5d92eca commit efddeeb

File tree

9 files changed

+48
-62
lines changed

9 files changed

+48
-62
lines changed

affinity-test/pom.xml

100755100644
File mode changed.

affinity/pom.xml

100755100644
File mode changed.

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

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@
3434
* @author peter.lawrey
3535
*/
3636
public class AffinityLock {
37-
private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLock.class);
38-
39-
// TODO It seems like on virtualized platforms .availableProcessors() value can change at
40-
// TODO runtime. We should think about how to adopt to such change
41-
4237
// Static fields and methods.
4338
public static final String AFFINITY_RESERVED = "affinity.reserved";
4439

40+
// TODO It seems like on virtualized platforms .availableProcessors() value can change at
41+
// TODO runtime. We should think about how to adopt to such change
4542
public static final int PROCESSORS = Runtime.getRuntime().availableProcessors();
4643
public static final long BASE_AFFINITY = AffinitySupport.getAffinity();
4744
public static final long RESERVED_AFFINITY = getReservedAffinity0();
48-
45+
private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLock.class);
4946
private static final LockInventory LOCK_INVENTORY = new LockInventory(new NoCpuLayout(PROCESSORS));
5047

5148
static {
@@ -57,10 +54,37 @@ public class AffinityLock {
5754
LOGGER.warn("Unable to load /proc/cpuinfo", e);
5855
}
5956
}
57+
/**
58+
* Logical ID of the CPU to which this lock belongs to.
59+
*/
60+
private final int cpuId;
61+
/**
62+
* CPU to which this lock belongs to is of general use.
63+
*/
64+
private final boolean base;
65+
/**
66+
* CPU to which this lock belongs to is reservable.
67+
*/
68+
private final boolean reservable;
69+
/**
70+
* An inventory build from the CPU layout which keeps track of the various locks
71+
* belonging to each CPU.
72+
*/
73+
private final LockInventory lockInventory;
74+
boolean bound = false;
75+
@Nullable
76+
Thread assignedThread;
77+
78+
AffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) {
79+
this.lockInventory = lockInventory;
80+
this.cpuId = cpuId;
81+
this.base = base;
82+
this.reservable = reservable;
83+
}
6084

6185
/**
6286
* Set the CPU layout for this machine. CPUs which are not mentioned will be ignored.
63-
* <p></p>
87+
* <p>
6488
* Changing the layout will have no impact on thread which have already been assigned.
6589
* It only affects subsequent assignments.
6690
*
@@ -102,7 +126,7 @@ public static AffinityLock acquireLock() {
102126

103127
/**
104128
* Assign any free core to this thread.
105-
* <p></p>
129+
* <p>
106130
* In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used.
107131
*
108132
* @return A handle for the current AffinityLock.
@@ -113,7 +137,7 @@ public static AffinityLock acquireCore() {
113137

114138
/**
115139
* Assign a cpu which can be bound to the current thread or another thread.
116-
* <p></p>
140+
* <p>
117141
* This can be used for defining your thread layout centrally and passing the handle via dependency injection.
118142
*
119143
* @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later.
@@ -125,7 +149,7 @@ public static AffinityLock acquireLock(boolean bind) {
125149

126150
/**
127151
* Assign a core(and all its cpus) which can be bound to the current thread or another thread.
128-
* <p></p>
152+
* <p>
129153
* This can be used for defining your thread layout centrally and passing the handle via dependency injection.
130154
*
131155
* @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later.
@@ -143,7 +167,6 @@ private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull Affini
143167
return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies);
144168
}
145169

146-
147170
/**
148171
* @return All the current locks as a String.
149172
*/
@@ -152,39 +175,6 @@ public static String dumpLocks() {
152175
return LOCK_INVENTORY.dumpLocks();
153176
}
154177

155-
/**
156-
* Logical ID of the CPU to which this lock belongs to.
157-
*/
158-
private final int cpuId;
159-
160-
/**
161-
* CPU to which this lock belongs to is of general use.
162-
*/
163-
private final boolean base;
164-
165-
/**
166-
* CPU to which this lock belongs to is reservable.
167-
*/
168-
private final boolean reservable;
169-
170-
/**
171-
* An inventory build from the CPU layout which keeps track of the various locks
172-
* belonging to each CPU.
173-
*/
174-
private final LockInventory lockInventory;
175-
176-
boolean bound = false;
177-
178-
@Nullable
179-
Thread assignedThread;
180-
181-
AffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) {
182-
this.lockInventory = lockInventory;
183-
this.cpuId = cpuId;
184-
this.base = base;
185-
this.reservable = reservable;
186-
}
187-
188178
/**
189179
* Assigning the current thread has a side effect of preventing the lock being used again until it is released.
190180
*
@@ -238,7 +228,7 @@ final boolean canReserve() {
238228

239229
/**
240230
* Give another affinity lock relative to this one based on a list of strategies.
241-
* <p></p>
231+
* <p>
242232
* The strategies are evaluated in order to (like a search path) to find the next appropriate thread.
243233
* If ANY is not the last strategy, a warning is logged and no cpu is assigned (leaving the OS to choose)
244234
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/**
2727
* This is a ThreadFactory which assigns threads based the strategies provided.
28-
* <p></p>
28+
* <p>
2929
* If no strategies are provided AffinityStrategies.ANY is used.
3030
*
3131
* @author peter.lawrey

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static AffinityLock acquireLock() {
4747

4848
/**
4949
* Assign any free core to this thread.
50-
* <p></p>
50+
* <p>
5151
* In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used.
5252
*
5353
* @return A handle for the current AffinityLock.
@@ -58,7 +58,7 @@ public static AffinityLock acquireCore() {
5858

5959
/**
6060
* Assign a cpu which can be bound to the current thread or another thread.
61-
* <p></p>
61+
* <p>
6262
* This can be used for defining your thread layout centrally and passing the handle via dependency injection.
6363
*
6464
* @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later.
@@ -70,7 +70,7 @@ public static AffinityLock acquireLock(boolean bind) {
7070

7171
/**
7272
* Assign a core(and all its cpus) which can be bound to the current thread or another thread.
73-
* <p></p>
73+
* <p>
7474
* This can be used for defining your thread layout centrally and passing the handle via dependency injection.
7575
*
7676
* @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later.
@@ -90,7 +90,7 @@ private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull Affini
9090

9191
/**
9292
* Set the CPU layout for this machine. CPUs which are not mentioned will be ignored.
93-
* <p></p>
93+
* <p>
9494
* Changing the layout will have no impact on thread which have already been assigned.
9595
* It only affects subsequent assignments.
9696
*

affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java

100755100644
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818

1919
package net.openhft.affinity.impl;
2020

21-
import com.sun.jna.LastErrorException;
22-
import com.sun.jna.Library;
23-
import com.sun.jna.Native;
24-
import com.sun.jna.Platform;
25-
import com.sun.jna.PointerType;
21+
import com.sun.jna.*;
2622
import com.sun.jna.ptr.IntByReference;
2723
import com.sun.jna.ptr.LongByReference;
2824
import net.openhft.affinity.IAffinity;
@@ -33,7 +29,7 @@
3329
* Implementation of {@link IAffinity} based on JNA call of
3430
* sched_setaffinity(3)/sched_getaffinity(3) from 'c' library. Applicable for most
3531
* linux/unix platforms
36-
* <p></p>
32+
* <p>
3733
* TODO Support assignment to core 64 and above
3834
*
3935
* @author peter.lawrey

affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java

100755100644
File mode changed.

affinity/src/test/java/org/junit/Assert.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
/**
2828
* TODO replace with 4.12 when it is released with a simple bug fix.
29-
* <p></p>
29+
* <p>
3030
* A set of assertion methods useful for writing tests. Only failed assertions
3131
* are recorded. These methods can be used directly:
3232
* <code>Assert.assertEquals(...)</code>, however, they read better if they
3333
* are referenced through static import:<br/>
34-
* <p></p>
34+
* <p>
3535
* <pre>
3636
* import static org.junit.Assert.*;
3737
* ...
@@ -827,15 +827,15 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
827827
* Asserts that <code>actual</code> satisfies the condition specified by
828828
* <code>matcher</code>. If not, an {@link AssertionError} is thrown with
829829
* information about the matcher and failing value. Example:
830-
* <p></p>
830+
* <p>
831831
* <pre>
832832
* assertThat(0, is(1)); // fails:
833833
* // failure message:
834834
* // expected: is &lt;1&gt;
835835
* // got value: &lt;0&gt;
836836
* assertThat(0, is(not(1))) // passes
837837
* </pre>
838-
* <p></p>
838+
* <p>
839839
* <code>org.hamcrest.Matcher</code> does not currently document the meaning
840840
* of its type parameter <code>T</code>. This method assumes that a matcher
841841
* typed as <code>Matcher&lt;T&gt;</code> can be meaningfully applied only
@@ -857,7 +857,7 @@ public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
857857
* Asserts that <code>actual</code> satisfies the condition specified by
858858
* <code>matcher</code>. If not, an {@link AssertionError} is thrown with
859859
* the reason and information about the matcher and failing value. Example:
860-
* <p></p>
860+
* <p>
861861
* <pre>
862862
* assertThat(&quot;Help! Integers don't work&quot;, 0, is(1)); // fails:
863863
* // failure message:
@@ -866,7 +866,7 @@ public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
866866
* // got value: &lt;0&gt;
867867
* assertThat(&quot;Zero is one&quot;, 0, is(not(1))) // passes
868868
* </pre>
869-
* <p></p>
869+
* <p>
870870
* <code>org.hamcrest.Matcher</code> does not currently document the meaning
871871
* of its type parameter <code>T</code>. This method assumes that a matcher
872872
* typed as <code>Matcher&lt;T&gt;</code> can be meaningfully applied only

pom.xml

100755100644
File mode changed.

0 commit comments

Comments
 (0)