changed synchronized from extension method to normal one

This commit is contained in:
Alex Tkachman
2012-01-24 14:48:09 +02:00
parent e61a9f62ba
commit 8176487c93
5 changed files with 9 additions and 10 deletions
@@ -96,7 +96,7 @@ public class IntrinsicMethods {
declareOverload(myStdLib.getLibraryScope().getFunctions("plus"), 1, STRING_PLUS);
declareOverload(myStdLib.getLibraryScope().getFunctions("Array"), 1, new NewArray());
declareOverload(myStdLib.getLibraryScope().getFunctions("sure"), 0, new Sure());
declareOverload(myStdLib.getLibraryScope().getFunctions("synchronized"), 1, new StupidSync());
declareOverload(myStdLib.getLibraryScope().getFunctions("synchronized"), 2, new StupidSync());
declareOverload(myStdLib.getLibraryScope().getFunctions("iterator"), 0, new IteratorIterator());
declareIntrinsicFunction("ByteIterator", "next", 0, ITERATOR_NEXT);
@@ -17,8 +17,7 @@ import java.util.List;
public class StupidSync implements IntrinsicMethod {
@Override
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, @Nullable PsiElement element, @Nullable List<JetExpression> arguments, StackValue receiver) {
receiver.put(receiver.type, v);
codegen.pushMethodArguments((JetCallExpression)element, Arrays.asList(JetTypeMapper.TYPE_FUNCTION0));
codegen.pushMethodArguments((JetCallExpression)element, Arrays.asList(JetTypeMapper.TYPE_OBJECT, JetTypeMapper.TYPE_FUNCTION0));
v.invokestatic("jet/runtime/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;");
StackValue.onStack(JetTypeMapper.TYPE_OBJECT).put(expectedType, v);
return StackValue.onStack(expectedType);
+1 -1
View File
@@ -8,7 +8,7 @@ class TypeInfo<out T> {
fun typeinfo<T>() : TypeInfo<T>
fun typeinfo<T>(expression : T) : TypeInfo<T>
fun <R> Any.synchronized(block : () -> R) : R
fun <R> synchronized(lock: Any, block : () -> R) : R
fun Any?.identityEquals(other : Any?) : Boolean // = this === other
@@ -11,16 +11,16 @@ fun thread(block: ()->Unit ) {
}
fun box() : String {
val ref = AtomicInteger()
val mtref = AtomicInteger()
val cdl = CountDownLatch(11)
for(i in 0..10) {
thread {
var current = 0
do {
current = ref.synchronized {
val v = ref.get() + 1
current = synchronized(mtref) {
val v = mtref.get() + 1
if(v < 100)
ref.set(v+1)
mtref.set(v+1)
v
}
}
@@ -29,5 +29,5 @@ fun box() : String {
}
}
cdl.await()
return if(ref.get() == 100) "OK" else ref.get().toString()
return if(mtref.get() == 100) "OK" else mtref.get().toString()
}
+1 -1
View File
@@ -10,7 +10,7 @@ fun measureTimeMillis(block: () -> Unit) : Long {
}
/**
Executes current block and returns elapsed time in milliseconds
Executes current block and returns elapsed time in nanoseconds
*/
fun measureTimeNano(block: () -> Unit) : Long {
val start = System.nanoTime()