Skip to content

Commit 218d434

Browse files
committed
Merge pull request #240 from ruby-concurrency/java-atomic-improvements
JavaAtomicFixnum and JavaAtomicBoolean - ThreadContext should not be an object field.
2 parents 0c0177b + 8a30c08 commit 218d434

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

ext/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
3333
public static class JavaAtomicBoolean extends RubyObject {
3434

3535
private AtomicBoolean atomicBoolean;
36-
private ThreadContext context;
3736

3837
public JavaAtomicBoolean(Ruby runtime, RubyClass metaClass) {
3938
super(runtime, metaClass);
@@ -42,14 +41,12 @@ public JavaAtomicBoolean(Ruby runtime, RubyClass metaClass) {
4241
@JRubyMethod
4342
public IRubyObject initialize(ThreadContext context, IRubyObject value) {
4443
atomicBoolean = new AtomicBoolean(convertRubyBooleanToJavaBoolean(value));
45-
this.context = context;
4644
return context.nil;
4745
}
4846

4947
@JRubyMethod
5048
public IRubyObject initialize(ThreadContext context) {
5149
atomicBoolean = new AtomicBoolean();
52-
this.context = context;
5350
return context.nil;
5451
}
5552

@@ -69,7 +66,7 @@ public IRubyObject isAtomicFalse() {
6966
}
7067

7168
@JRubyMethod(name = "value=")
72-
public IRubyObject setAtomic(IRubyObject newValue) {
69+
public IRubyObject setAtomic(ThreadContext context, IRubyObject newValue) {
7370
atomicBoolean.set(convertRubyBooleanToJavaBoolean(newValue));
7471
return context.nil;
7572
}

ext/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.concurrent_ruby.ext;
22

3+
34
import java.io.IOException;
45
import java.util.concurrent.atomic.AtomicLong;
56
import org.jruby.Ruby;
@@ -22,7 +23,6 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
2223
RubyClass atomicCls = concurrentMod.defineClassUnder("JavaAtomicFixnum", runtime.getObject(), JRUBYREFERENCE_ALLOCATOR);
2324

2425
atomicCls.defineAnnotatedMethods(JavaAtomicFixnum.class);
25-
2626
}
2727

2828
private static final ObjectAllocator JRUBYREFERENCE_ALLOCATOR = new ObjectAllocator() {
@@ -35,7 +35,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
3535
public static class JavaAtomicFixnum extends RubyObject {
3636

3737
private AtomicLong atomicLong;
38-
private ThreadContext context;
3938

4039
public JavaAtomicFixnum(Ruby runtime, RubyClass metaClass) {
4140
super(runtime, metaClass);
@@ -44,14 +43,12 @@ public JavaAtomicFixnum(Ruby runtime, RubyClass metaClass) {
4443
@JRubyMethod
4544
public IRubyObject initialize(ThreadContext context) {
4645
this.atomicLong = new AtomicLong(0);
47-
this.context = context;
4846
return context.nil;
4947
}
5048

5149
@JRubyMethod
5250
public IRubyObject initialize(ThreadContext context, IRubyObject value) {
5351
this.atomicLong = new AtomicLong(rubyFixnumToLong(value));
54-
this.context = context;
5552
return context.nil;
5653
}
5754

@@ -61,7 +58,7 @@ public IRubyObject getValue() {
6158
}
6259

6360
@JRubyMethod(name = "value=")
64-
public IRubyObject setValue(IRubyObject newValue) {
61+
public IRubyObject setValue(ThreadContext context, IRubyObject newValue) {
6562
atomicLong.set(rubyFixnumToLong(newValue));
6663
return context.nil;
6764
}
@@ -77,7 +74,7 @@ public IRubyObject decrement() {
7774
}
7875

7976
@JRubyMethod(name = "compare_and_set")
80-
public IRubyObject compareAndSet(IRubyObject expect, IRubyObject update) {
77+
public IRubyObject compareAndSet(ThreadContext context, IRubyObject expect, IRubyObject update) {
8178
return RubyBoolean.newBoolean(getRuntime(), atomicLong.compareAndSet(rubyFixnumToLong(expect), rubyFixnumToLong(update)));
8279
}
8380

0 commit comments

Comments
 (0)