From 9406bce795fc2043ecc7477c52e271a0fa2ae857 Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Mon, 23 Jul 2007 08:21:05 -0400 Subject: [PATCH] non-blocking thunks for Java --- java/concurrent/FuturesService.java | 40 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/java/concurrent/FuturesService.java b/java/concurrent/FuturesService.java index 13cff10..bc3b5ca 100644 --- a/java/concurrent/FuturesService.java +++ b/java/concurrent/FuturesService.java @@ -49,8 +49,8 @@ public class FuturesService implements BasicLibraryService { } public static class Thunk extends RubyObject { - private IRubyObject source; - private IRubyObject value; + private volatile IRubyObject source; + private volatile IRubyObject value; Thunk(Ruby runtime, RubyClass klass, IRubyObject source) { super(runtime, klass, false); @@ -78,27 +78,23 @@ public class FuturesService implements BasicLibraryService { while (obj instanceof Thunk) { Thunk thunk=(Thunk)obj; - synchronized (thunk) { - if ( thunk.source != null ) { - if (evaluate) { - thunk.value = thunk.source.callMethod(thunk.source.getRuntime().getCurrentContext(), "value"); - thunk.source = null; - } - - if ( obj != original ) { - Thunk original_thunk = (Thunk)original; - synchronized (original_thunk) { - original_thunk.value = thunk.value; - } - } - - if (!evaluate) { - break; - } + if ( thunk.value == null ) { + if (evaluate) { + thunk.value = thunk.source.callMethod(thunk.source.getRuntime().getCurrentContext(), "value"); + thunk.source = null; } - obj = thunk.value; + if ( obj != original ) { + Thunk original_thunk = (Thunk)original; + original_thunk.value = thunk.value; + } + + if (!evaluate) { + break; + } } + + obj = thunk.value; } return obj; @@ -130,9 +126,7 @@ public class FuturesService implements BasicLibraryService { if ( name == "inspect" && args.length == 1 ) { Thunk thunk = (Thunk)self; IRubyObject source; - synchronized (thunk) { - source = thunk.source; - } + source = thunk.source; if ( source != null ) { Ruby runtime = getRuntime(); return runtime.newString("#"); -- 2.11.4.GIT