mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Unsafe tests for AtomicLong
This commit is contained in:
parent
4aa282176e
commit
1d342d8d88
@ -18,6 +18,7 @@ package de.inetsoftware.jwebassembly.runtime;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
@ -45,7 +46,11 @@ public class UnsafeTest extends AbstractBaseTest {
|
|||||||
addParam( list, script, "compareAndSwapInt" );
|
addParam( list, script, "compareAndSwapInt" );
|
||||||
addParam( list, script, "getAndAddInt" );
|
addParam( list, script, "getAndAddInt" );
|
||||||
addParam( list, script, "getAndSetInt" );
|
addParam( list, script, "getAndSetInt" );
|
||||||
addParam( list, script, "lazySet" );
|
addParam( list, script, "lazySetInt" );
|
||||||
|
addParam( list, script, "compareAndSwapLong" );
|
||||||
|
addParam( list, script, "getAndAddLong" );
|
||||||
|
addParam( list, script, "getAndSetLong" );
|
||||||
|
addParam( list, script, "lazySetLong" );
|
||||||
}
|
}
|
||||||
rule.setTestParameters( list );
|
rule.setTestParameters( list );
|
||||||
return list;
|
return list;
|
||||||
@ -86,10 +91,49 @@ public class UnsafeTest extends AbstractBaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static int lazySet() {
|
static int lazySetInt() {
|
||||||
AtomicInteger obj = new AtomicInteger();
|
AtomicInteger obj = new AtomicInteger();
|
||||||
obj.lazySet( 42 );
|
obj.lazySet( 42 );
|
||||||
return obj.get();
|
return obj.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static long compareAndSwapLong() {
|
||||||
|
AtomicLong obj = new AtomicLong();
|
||||||
|
if( obj.compareAndSet( 0, 25 ) ) {
|
||||||
|
return obj.get();
|
||||||
|
} else {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static long getAndAddLong() {
|
||||||
|
AtomicLong obj = new AtomicLong();
|
||||||
|
obj.set( 13 );
|
||||||
|
if( obj.getAndAdd( 25 ) == 13 ) {
|
||||||
|
return obj.get();
|
||||||
|
} else {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static long getAndSetLong() {
|
||||||
|
AtomicLong obj = new AtomicLong();
|
||||||
|
obj.set( 13 );
|
||||||
|
if( obj.getAndSet( 25 ) == 13 ) {
|
||||||
|
return obj.get();
|
||||||
|
} else {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static long lazySetLong() {
|
||||||
|
AtomicLong obj = new AtomicLong();
|
||||||
|
obj.lazySet( 42 );
|
||||||
|
return obj.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user