summaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/common/util/locks
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-03 16:06:47 +0200
committerSven Gothel <[email protected]>2014-07-03 16:06:47 +0200
commitdf9ff7f340a5ab4e07efc613f5f264eeae63d4c7 (patch)
tree239ae276b82024b140428e6c0fe5d739fdd686a4 /src/junit/com/jogamp/common/util/locks
parenteb47aaba63e3b1bf55f274a0f338f1010a017ae4 (diff)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74) - Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Add final modifier to private fields - Add final modifier to method parameters - Add final modifier to local variables - Remove unnecessary casts - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines
Diffstat (limited to 'src/junit/com/jogamp/common/util/locks')
-rw-r--r--src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java356
-rw-r--r--src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java106
-rw-r--r--src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java16
-rw-r--r--src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java4
-rw-r--r--src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java4
5 files changed, 243 insertions, 243 deletions
diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java
index df5f3ba..26677c0 100644
--- a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java
+++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java
@@ -3,14 +3,14 @@
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
@@ -20,12 +20,12 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-
+
package com.jogamp.common.util.locks;
import java.io.IOException;
@@ -47,16 +47,16 @@ import org.junit.runners.MethodSorters;
public class TestRecursiveLock01 extends JunitTracer {
public enum YieldMode {
- NONE(0), YIELD(1), SLEEP(2);
-
+ NONE(0), YIELD(1), SLEEP(2);
+
public final int id;
- YieldMode(int id){
+ YieldMode(final int id){
this.id = id;
}
- }
-
- static void yield(YieldMode mode) {
+ }
+
+ static void yield(final YieldMode mode) {
switch(mode) {
case YIELD:
Thread.yield();
@@ -64,7 +64,7 @@ public class TestRecursiveLock01 extends JunitTracer {
case SLEEP:
try {
Thread.sleep(10);
- } catch (InterruptedException ie) {
+ } catch (final InterruptedException ie) {
ie.printStackTrace();
}
break;
@@ -76,7 +76,7 @@ public class TestRecursiveLock01 extends JunitTracer {
static class LockedObject {
static final boolean DEBUG = false;
-
+
static class ThreadStat {
ThreadStat() {
total = 0;
@@ -85,16 +85,16 @@ public class TestRecursiveLock01 extends JunitTracer {
long total; // ns
int counter;
}
-
- private RecursiveLock locker; // post
+
+ private final RecursiveLock locker; // post
private int deferredThreadCount = 0; // synced
- private Map<String, ThreadStat> threadWaitMap = Collections.synchronizedMap(new HashMap<String, ThreadStat>()); // locked
-
- long avrg; // ns, post
+ private final Map<String, ThreadStat> threadWaitMap = Collections.synchronizedMap(new HashMap<String, ThreadStat>()); // locked
+
+ long avrg; // ns, post
long max_deviation; // ns, post
long min_deviation; // ns, post
- public LockedObject(LockFactory.ImplType implType, boolean fair) {
+ public LockedObject(final LockFactory.ImplType implType, final boolean fair) {
locker = LockFactory.createRecursiveLock(implType, fair);
}
@@ -107,8 +107,8 @@ public class TestRecursiveLock01 extends JunitTracer {
public synchronized int getDeferredThreadCount() {
return deferredThreadCount;
}
-
- public final void action1Direct(int l, YieldMode yieldMode) {
+
+ public final void action1Direct(int l, final YieldMode yieldMode) {
if(DEBUG) {
System.err.print("<a1");
}
@@ -133,13 +133,13 @@ public class TestRecursiveLock01 extends JunitTracer {
class Action2 implements Runnable {
int l;
YieldMode yieldMode;
-
- Action2(int l, YieldMode yieldMode) {
+
+ Action2(final int l, final YieldMode yieldMode) {
this.l=l;
this.yieldMode=yieldMode;
incrDeferredThreadCount();
}
-
+
public void run() {
if(DEBUG) {
System.err.print("[a2");
@@ -165,11 +165,11 @@ public class TestRecursiveLock01 extends JunitTracer {
if(0>dc) {
throw new InternalError("deferredThreads: "+dc);
}
- }
+ }
}
- public final void action2Deferred(int l, YieldMode yieldMode) {
- Action2 action2 = new Action2(l, yieldMode);
+ public final void action2Deferred(final int l, final YieldMode yieldMode) {
+ final Action2 action2 = new Action2(l, yieldMode);
new Thread(action2, Thread.currentThread().getName()+"-deferred").start();
}
@@ -177,7 +177,7 @@ public class TestRecursiveLock01 extends JunitTracer {
long td = System.nanoTime();
locker.lock();
td = System.nanoTime() - td;
-
+
final String cur = Thread.currentThread().getName();
ThreadStat ts = threadWaitMap.get(cur);
if(null == ts) {
@@ -195,37 +195,37 @@ public class TestRecursiveLock01 extends JunitTracer {
public final boolean isLocked() {
return locker.isLocked();
}
-
- public void stats(boolean dump) {
+
+ public void stats(final boolean dump) {
long timeAllLocks=0;
int numAllLocks=0;
- for(Iterator<String> i = threadWaitMap.keySet().iterator(); i.hasNext(); ) {
- String name = i.next();
- ThreadStat ts = threadWaitMap.get(name);
+ for(final Iterator<String> i = threadWaitMap.keySet().iterator(); i.hasNext(); ) {
+ final String name = i.next();
+ final ThreadStat ts = threadWaitMap.get(name);
timeAllLocks += ts.total;
numAllLocks += ts.counter;
- }
+ }
max_deviation = Long.MIN_VALUE;
min_deviation = Long.MAX_VALUE;
avrg = timeAllLocks/numAllLocks;
if(dump) {
- System.err.printf("Average: %6d ms / %6d times = %8d ns",
+ System.err.printf("Average: %6d ms / %6d times = %8d ns",
timeAllLocks/1000000, numAllLocks, avrg);
System.err.println();
}
- for(Iterator<String> i = threadWaitMap.keySet().iterator(); i.hasNext(); numAllLocks++) {
- String name = i.next();
+ for(final Iterator<String> i = threadWaitMap.keySet().iterator(); i.hasNext(); numAllLocks++) {
+ final String name = i.next();
final ThreadStat ts = threadWaitMap.get(name);
final long a = ts.total/ts.counter;
final long d = a - avrg;
max_deviation = Math.max(max_deviation, d);
min_deviation = Math.min(min_deviation, d);
if(dump) {
- System.err.printf("%-35s %12d ns / %6d times, a %8d ns, d %8d ns",
+ System.err.printf("%-35s %12d ns / %6d times, a %8d ns, d %8d ns",
name, ts.total, ts.counter, a, d);
System.err.println();
}
- }
+ }
if(dump) {
System.err.printf("Deviation (min/max): [%8d ns - %8d ns]", min_deviation, max_deviation);
System.err.println();
@@ -248,7 +248,7 @@ public class TestRecursiveLock01 extends JunitTracer {
int iloops;
YieldMode yieldMode;
- public LockedObjectRunner1(LockedObject lo, int loops, int iloops, YieldMode yieldMode) {
+ public LockedObjectRunner1(final LockedObject lo, final int loops, final int iloops, final YieldMode yieldMode) {
this.lo = lo;
this.loops = loops;
this.iloops = iloops;
@@ -264,18 +264,18 @@ public class TestRecursiveLock01 extends JunitTracer {
public final boolean isStopped() {
return stopped;
}
-
+
public void waitUntilStopped() {
synchronized(this) {
while(!stopped) {
try {
this.wait();
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
e.printStackTrace();
}
}
}
-
+
}
public void run() {
@@ -291,18 +291,18 @@ public class TestRecursiveLock01 extends JunitTracer {
}
}
- protected long testLockedObjectImpl(LockFactory.ImplType implType, boolean fair,
- int threadNum, int loops, int iloops, YieldMode yieldMode) throws InterruptedException {
+ protected long testLockedObjectImpl(final LockFactory.ImplType implType, final boolean fair,
+ final int threadNum, final int loops, final int iloops, final YieldMode yieldMode) throws InterruptedException {
final long t0 = System.currentTimeMillis();
- LockedObject lo = new LockedObject(implType, fair);
- LockedObjectRunner[] runners = new LockedObjectRunner[threadNum];
- Thread[] threads = new Thread[threadNum];
+ final LockedObject lo = new LockedObject(implType, fair);
+ final LockedObjectRunner[] runners = new LockedObjectRunner[threadNum];
+ final Thread[] threads = new Thread[threadNum];
int i;
for(i=0; i<threadNum; i++) {
runners[i] = new LockedObjectRunner1(lo, loops, iloops, yieldMode);
// String name = Thread.currentThread().getName()+"-ActionThread-"+i+"_of_"+threadNum;
- String name = "ActionThread-"+i+"_of_"+threadNum;
+ final String name = "ActionThread-"+i+"_of_"+threadNum;
threads[i] = new Thread( runners[i], name );
threads[i].start();
}
@@ -312,17 +312,17 @@ public class TestRecursiveLock01 extends JunitTracer {
}
while( 0 < lo.getDeferredThreadCount() ) {
Thread.sleep(100);
- }
+ }
Assert.assertEquals(0, lo.locker.getHoldCount());
Assert.assertEquals(false, lo.locker.isLocked());
Assert.assertEquals(0, lo.getDeferredThreadCount());
-
+
final long dt = System.currentTimeMillis()-t0;
lo.stats(false);
-
+
System.err.println();
final String fair_S = fair ? "fair " : "unfair" ;
- System.err.printf("---- TestRecursiveLock01.testLockedObjectThreading: i %5s, %s, threads %2d, loops-outter %6d, loops-inner %6d, yield %5s - dt %6d ms, avrg %8d ns, deviation [ %8d .. %8d ] ns",
+ System.err.printf("---- TestRecursiveLock01.testLockedObjectThreading: i %5s, %s, threads %2d, loops-outter %6d, loops-inner %6d, yield %5s - dt %6d ms, avrg %8d ns, deviation [ %8d .. %8d ] ns",
implType, fair_S, threadNum, loops, iloops, yieldMode, dt, lo.avrg, lo.min_deviation, lo.max_deviation);
System.err.println();
return dt;
@@ -330,247 +330,247 @@ public class TestRecursiveLock01 extends JunitTracer {
@Test
public void testLockedObjectThreading5x1000x10000N_Int01_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=true;
- int threadNum=5;
- int loops=1000;
- int iloops=10000;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=true;
+ int threadNum=5;
+ int loops=1000;
+ int iloops=10000;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading5x1000x10000N_Java5_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=true;
- int threadNum=5;
- int loops=1000;
- int iloops=10000;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=true;
+ int threadNum=5;
+ int loops=1000;
+ int iloops=10000;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
-
+
@Test
public void testLockedObjectThreading5x1000x10000N_Int01_Unfair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=false;
- int threadNum=5;
- int loops=1000;
- int iloops=10000;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=false;
+ int threadNum=5;
+ int loops=1000;
+ int iloops=10000;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading5x1000x10000N_Java5_Unfair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=false;
- int threadNum=5;
- int loops=1000;
- int iloops=10000;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=false;
+ int threadNum=5;
+ int loops=1000;
+ int iloops=10000;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
-
+
@Test
public void testLockedObjectThreading25x100x100Y_Int01_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.YIELD;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.YIELD;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
- testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
+
+ testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100Y_Java5_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.YIELD;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.YIELD;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
- testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
+
+ testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100Y_Int01_Unair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=false;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.YIELD;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=false;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.YIELD;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
- testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
+
+ testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100Y_Java5_Unfair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=false;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.YIELD;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=false;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.YIELD;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
- testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
+
+ testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
// @Test
public void testLockedObjectThreading25x100x100S_Int01_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.SLEEP;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.SLEEP;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
// @Test
public void testLockedObjectThreading25x100x100S_Java5() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.SLEEP;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.SLEEP;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100N_Int01_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100N_Java5_Fair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=true;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=true;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100N_Int01_Unfair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int01;
- boolean fair=false;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int01;
+ final boolean fair=false;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
@Test
public void testLockedObjectThreading25x100x100N_Java5_Unfair() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Java5;
- boolean fair=false;
- int threadNum=25;
- int loops=100;
- int iloops=100;
- YieldMode yieldMode=YieldMode.NONE;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Java5;
+ final boolean fair=false;
+ int threadNum=25;
+ int loops=100;
+ int iloops=100;
+ final YieldMode yieldMode=YieldMode.NONE;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
threadNum=5; loops=5; iloops=10;
}
-
+
testLockedObjectImpl(t, fair, threadNum, loops, iloops, yieldMode);
}
- static int atoi(String a) {
+ static int atoi(final String a) {
int i=0;
try {
i = Integer.parseInt(a);
- } catch (Exception ex) { ex.printStackTrace(); }
+ } catch (final Exception ex) { ex.printStackTrace(); }
return i;
}
- public static void main(String args[]) throws IOException, InterruptedException {
- String tstname = TestRecursiveLock01.class.getName();
+ public static void main(final String args[]) throws IOException, InterruptedException {
+ final String tstname = TestRecursiveLock01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
-
+
/**
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.err.println("Press enter to continue");
- System.err.println(stdin.readLine());
+ System.err.println(stdin.readLine());
TestRecursiveLock01 t = new TestRecursiveLock01();
t.testLockedObjectThreading5x1000x10000N_Int01_Unfair();
-
+
t.testLockedObjectThreading5x1000x10000N_Int01_Fair();
t.testLockedObjectThreading5x1000x10000N_Java5_Fair();
t.testLockedObjectThreading5x1000x10000N_Int01_Unfair();
diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java
index 51cc0ac..b361463 100644
--- a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java
+++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java
@@ -3,14 +3,14 @@
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
@@ -20,12 +20,12 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-
+
package com.jogamp.common.util.locks;
import java.io.IOException;
@@ -43,16 +43,16 @@ import org.junit.runners.MethodSorters;
public class TestRecursiveThreadGroupLock01 extends JunitTracer {
public enum YieldMode {
- NONE(0), YIELD(1), SLEEP(2);
-
+ NONE(0), YIELD(1), SLEEP(2);
+
public final int id;
- YieldMode(int id){
+ YieldMode(final int id){
this.id = id;
}
- }
-
- static void yield(YieldMode mode) {
+ }
+
+ static void yield(final YieldMode mode) {
switch(mode) {
case YIELD:
Thread.yield();
@@ -60,7 +60,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
case SLEEP:
try {
Thread.sleep(10);
- } catch (InterruptedException ie) {
+ } catch (final InterruptedException ie) {
ie.printStackTrace();
}
break;
@@ -72,8 +72,8 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
static class LockedObject {
static final boolean DEBUG = false;
-
- private RecursiveThreadGroupLock locker; // post
+
+ private final RecursiveThreadGroupLock locker; // post
private volatile int slaveCounter;
public LockedObject() {
@@ -81,7 +81,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
slaveCounter = 0;
}
- public final void masterAction(String tab, String name, Thread[] slaves, int loops, int mark, final YieldMode yieldMode) {
+ public final void masterAction(final String tab, final String name, final Thread[] slaves, final int loops, final int mark, final YieldMode yieldMode) {
locker.lock();
if(DEBUG) {
System.err.println(tab+"<"+name+" c "+slaveCounter);
@@ -107,12 +107,12 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
}
}
- public final void slaveAction(String tab, String name, int loops, int mark, YieldMode yieldMode) {
+ public final void slaveAction(final String tab, final String name, int loops, final int mark, final YieldMode yieldMode) {
if(slaveCounter>=mark) {
if(DEBUG) {
System.err.println(tab+"["+name+" c "+slaveCounter+" - NOP]");
}
- return;
+ return;
}
locker.lock();
if(DEBUG) {
@@ -141,7 +141,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
public final boolean isLocked() {
return locker.isLocked();
}
-
+
}
interface LockedObjectRunner extends Runnable {
@@ -163,7 +163,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
YieldMode yieldMode;
/** master constructor */
- public LockedObjectRunner1(String tab, String name, LockedObject lo, Thread[] slaves, int loops, int mark, YieldMode yieldMode) {
+ public LockedObjectRunner1(final String tab, final String name, final LockedObject lo, final Thread[] slaves, final int loops, final int mark, final YieldMode yieldMode) {
this.tab = tab;
this.name = name;
this.lo = lo;
@@ -178,7 +178,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
}
/** slave constructor */
- public LockedObjectRunner1(String tab, String name, LockedObject lo, int loops, int mark, YieldMode yieldMode) {
+ public LockedObjectRunner1(final String tab, final String name, final LockedObject lo, final int loops, final int mark, final YieldMode yieldMode) {
this.tab = tab;
this.name = name;
this.lo = lo;
@@ -191,7 +191,7 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
Assert.assertTrue(mark>loops);
Assert.assertTrue(loops*loops>mark);
}
-
+
public final void stop() {
shouldStop = true;
}
@@ -202,18 +202,18 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
public final boolean isStopped() {
return stopped;
}
-
+
public void waitUntilStopped() {
synchronized(this) {
while(!stopped) {
try {
this.wait();
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
e.printStackTrace();
}
}
}
-
+
}
public void run() {
@@ -232,28 +232,28 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
}
}
- protected long testLockedObjectImpl(LockFactory.ImplType implType, boolean fair,
- int slaveThreadNum, int concurrentThreadNum,
- int loops, int mark, YieldMode yieldMode) throws InterruptedException {
+ protected long testLockedObjectImpl(final LockFactory.ImplType implType, final boolean fair,
+ final int slaveThreadNum, final int concurrentThreadNum,
+ final int loops, final int mark, final YieldMode yieldMode) throws InterruptedException {
final long t0 = System.currentTimeMillis();
- LockedObject lo = new LockedObject();
- LockedObjectRunner[] concurrentRunners = new LockedObjectRunner[concurrentThreadNum];
- LockedObjectRunner[] slaveRunners = new LockedObjectRunner[slaveThreadNum];
- Thread[] concurrentThreads = new Thread[concurrentThreadNum];
- Thread[] slaveThreads = new Thread[slaveThreadNum];
- Thread[] noCoOwnerThreads = new Thread[0];
+ final LockedObject lo = new LockedObject();
+ final LockedObjectRunner[] concurrentRunners = new LockedObjectRunner[concurrentThreadNum];
+ final LockedObjectRunner[] slaveRunners = new LockedObjectRunner[slaveThreadNum];
+ final Thread[] concurrentThreads = new Thread[concurrentThreadNum];
+ final Thread[] slaveThreads = new Thread[slaveThreadNum];
+ final Thread[] noCoOwnerThreads = new Thread[0];
int i;
for(i=0; i<slaveThreadNum; i++) {
slaveRunners[i] = new LockedObjectRunner1(" ", "s"+i, lo, loops, mark, yieldMode);
- String name = "ActionThread-Slaves-"+i+"_of_"+slaveThreadNum;
+ final String name = "ActionThread-Slaves-"+i+"_of_"+slaveThreadNum;
slaveThreads[i] = new Thread( slaveRunners[i], name );
}
for(i=0; i<concurrentThreadNum; i++) {
String name;
if(i==0) {
concurrentRunners[i] = new LockedObjectRunner1("", "M0", lo, slaveThreads, loops, mark, yieldMode);
- name = "ActionThread-Master-"+i+"_of_"+concurrentThreadNum;
+ name = "ActionThread-Master-"+i+"_of_"+concurrentThreadNum;
} else {
concurrentRunners[i] = new LockedObjectRunner1(" ", "O"+i, lo, noCoOwnerThreads, loops, mark, yieldMode);
name = "ActionThread-Others-"+i+"_of_"+concurrentThreadNum;
@@ -276,45 +276,45 @@ public class TestRecursiveThreadGroupLock01 extends JunitTracer {
}
Assert.assertEquals(0, lo.locker.getHoldCount());
Assert.assertEquals(false, lo.locker.isLocked());
-
+
final long dt = System.currentTimeMillis()-t0;
-
+
System.err.println();
final String fair_S = fair ? "fair " : "unfair" ;
- System.err.printf("---- TestRecursiveLock01.testLockedObjectThreading: i %5s, %s, threads %2d, loops-outter %6d, loops-inner %6d, yield %5s - dt %6d ms",
+ System.err.printf("---- TestRecursiveLock01.testLockedObjectThreading: i %5s, %s, threads %2d, loops-outter %6d, loops-inner %6d, yield %5s - dt %6d ms",
implType, fair_S, concurrentThreadNum, loops, mark, yieldMode, dt);
System.err.println();
return dt;
}
-
+
@Test
public void testTwoThreadsInGroup() throws InterruptedException {
- LockFactory.ImplType t = LockFactory.ImplType.Int02ThreadGroup;
- boolean fair=true;
- int coOwnerThreadNum=2;
- int threadNum=5;
- int loops=1000;
- int mark=10000;
- YieldMode yieldMode=YieldMode.YIELD;
-
+ final LockFactory.ImplType t = LockFactory.ImplType.Int02ThreadGroup;
+ final boolean fair=true;
+ final int coOwnerThreadNum=2;
+ final int threadNum=5;
+ int loops=1000;
+ int mark=10000;
+ final YieldMode yieldMode=YieldMode.YIELD;
+
if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
loops=5; mark=10;
}
-
+
testLockedObjectImpl(t, fair, coOwnerThreadNum, threadNum, loops, mark, yieldMode);
}
- public static void main(String args[]) throws IOException, InterruptedException {
- String tstname = TestRecursiveThreadGroupLock01.class.getName();
+ public static void main(final String args[]) throws IOException, InterruptedException {
+ final String tstname = TestRecursiveThreadGroupLock01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
-
+
/**
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.err.println("Press enter to continue");
- System.err.println(stdin.readLine());
+ System.err.println(stdin.readLine());
TestRecursiveLock01 t = new TestRecursiveLock01();
t.testLockedObjectThreading5x1000x10000N_Int01_Unfair();
-
+
t.testLockedObjectThreading5x1000x10000N_Int01_Fair();
t.testLockedObjectThreading5x1000x10000N_Java5_Fair();
t.testLockedObjectThreading5x1000x10000N_Int01_Unfair();
diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java
index c699e2e..775d46f 100644
--- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java
+++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java
@@ -60,22 +60,22 @@ public class TestSingletonServerSocket00 {
@Test
public void test2ndInstanceLockTimeout() {
Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO));
- SingletonInstance instanceTwo = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT);
+ final SingletonInstance instanceTwo = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT);
Assert.assertFalse("Could lock 2nd instance: "+instanceTwo.getName(), instanceTwo.tryLock(1000)); // 10x
System.gc(); // force cleanup
singletonInstance.unlock();
}
- private Thread startLockUnlockOffThread(int i) {
+ private Thread startLockUnlockOffThread(final int i) {
final Thread t = new Thread(new Runnable() {
public void run() {
- SingletonInstance myLock = SingletonInstance.createServerSocket(10, SINGLE_INSTANCE_LOCK_PORT);
+ final SingletonInstance myLock = SingletonInstance.createServerSocket(10, SINGLE_INSTANCE_LOCK_PORT);
System.err.println(Thread.currentThread().getName()+" LOCK try ..");
Assert.assertTrue(Thread.currentThread().getName()+" - Could not lock instance: "+myLock.getName(), myLock.tryLock(1000));
System.err.println(Thread.currentThread().getName()+" LOCK ON");
try {
Thread.sleep(300);
- } catch (InterruptedException e) { }
+ } catch (final InterruptedException e) { }
myLock.unlock();
System.err.println(Thread.currentThread().getName()+" LOCK OFF");
}
@@ -87,8 +87,8 @@ public class TestSingletonServerSocket00 {
@Test
public void testOffthreadLockUnlock() throws InterruptedException {
Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO));
- Thread t1 = startLockUnlockOffThread(1);
- Thread t2 = startLockUnlockOffThread(2);
+ final Thread t1 = startLockUnlockOffThread(1);
+ final Thread t2 = startLockUnlockOffThread(2);
Thread.sleep(300);
System.gc(); // force cleanup
singletonInstance.unlock();
@@ -97,8 +97,8 @@ public class TestSingletonServerSocket00 {
}
}
- public static void main(String args[]) throws IOException, InterruptedException {
- String tstname = TestSingletonServerSocket00.class.getName();
+ public static void main(final String args[]) throws IOException, InterruptedException {
+ final String tstname = TestSingletonServerSocket00.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
}
diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java
index 4bdc9bf..82ca89b 100644
--- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java
+++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java
@@ -56,8 +56,8 @@ public class TestSingletonServerSocket01 {
singletonInstance.unlock();
}
- public static void main(String args[]) throws IOException, InterruptedException {
- String tstname = TestSingletonServerSocket01.class.getName();
+ public static void main(final String args[]) throws IOException, InterruptedException {
+ final String tstname = TestSingletonServerSocket01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
}
diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java
index cb862ce..50eebd6 100644
--- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java
+++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java
@@ -68,8 +68,8 @@ public class TestSingletonServerSocket02 {
Thread.sleep(3000);
}
- public static void main(String args[]) throws IOException, InterruptedException {
- String tstname = TestSingletonServerSocket02.class.getName();
+ public static void main(final String args[]) throws IOException, InterruptedException {
+ final String tstname = TestSingletonServerSocket02.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
}