From 8a30c08a40d326e8fe8b70c8e9cf6089389d2d64 Mon Sep 17 00:00:00 2001 From: Lucas Allan Amorim Date: Wed, 11 Feb 2015 15:13:16 -0800 Subject: [PATCH] Improves JavaAtomicFixnum and JavaAtomicBoolean - ThreadContext should not be an object field. --- .../concurrent_ruby/ext/JavaAtomicBooleanLibrary.java | 5 +---- ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/ext/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java b/ext/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java index 90ee5189c..07d5265c1 100644 --- a/ext/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java +++ b/ext/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java @@ -33,7 +33,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) { public static class JavaAtomicBoolean extends RubyObject { private AtomicBoolean atomicBoolean; - private ThreadContext context; public JavaAtomicBoolean(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); @@ -42,14 +41,12 @@ public JavaAtomicBoolean(Ruby runtime, RubyClass metaClass) { @JRubyMethod public IRubyObject initialize(ThreadContext context, IRubyObject value) { atomicBoolean = new AtomicBoolean(convertRubyBooleanToJavaBoolean(value)); - this.context = context; return context.nil; } @JRubyMethod public IRubyObject initialize(ThreadContext context) { atomicBoolean = new AtomicBoolean(); - this.context = context; return context.nil; } @@ -69,7 +66,7 @@ public IRubyObject isAtomicFalse() { } @JRubyMethod(name = "value=") - public IRubyObject setAtomic(IRubyObject newValue) { + public IRubyObject setAtomic(ThreadContext context, IRubyObject newValue) { atomicBoolean.set(convertRubyBooleanToJavaBoolean(newValue)); return context.nil; } diff --git a/ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java b/ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java index 7fc89beee..9445f7c6f 100755 --- a/ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java +++ b/ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java @@ -1,5 +1,6 @@ package com.concurrent_ruby.ext; + import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; import org.jruby.Ruby; @@ -22,7 +23,6 @@ public void load(Ruby runtime, boolean wrap) throws IOException { RubyClass atomicCls = concurrentMod.defineClassUnder("JavaAtomicFixnum", runtime.getObject(), JRUBYREFERENCE_ALLOCATOR); atomicCls.defineAnnotatedMethods(JavaAtomicFixnum.class); - } private static final ObjectAllocator JRUBYREFERENCE_ALLOCATOR = new ObjectAllocator() { @@ -35,7 +35,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) { public static class JavaAtomicFixnum extends RubyObject { private AtomicLong atomicLong; - private ThreadContext context; public JavaAtomicFixnum(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); @@ -44,14 +43,12 @@ public JavaAtomicFixnum(Ruby runtime, RubyClass metaClass) { @JRubyMethod public IRubyObject initialize(ThreadContext context) { this.atomicLong = new AtomicLong(0); - this.context = context; return context.nil; } @JRubyMethod public IRubyObject initialize(ThreadContext context, IRubyObject value) { this.atomicLong = new AtomicLong(rubyFixnumToLong(value)); - this.context = context; return context.nil; } @@ -61,7 +58,7 @@ public IRubyObject getValue() { } @JRubyMethod(name = "value=") - public IRubyObject setValue(IRubyObject newValue) { + public IRubyObject setValue(ThreadContext context, IRubyObject newValue) { atomicLong.set(rubyFixnumToLong(newValue)); return context.nil; } @@ -77,7 +74,7 @@ public IRubyObject decrement() { } @JRubyMethod(name = "compare_and_set") - public IRubyObject compareAndSet(IRubyObject expect, IRubyObject update) { + public IRubyObject compareAndSet(ThreadContext context, IRubyObject expect, IRubyObject update) { return RubyBoolean.newBoolean(getRuntime(), atomicLong.compareAndSet(rubyFixnumToLong(expect), rubyFixnumToLong(update))); }