1
1
package com .concurrent_ruby .ext ;
2
2
3
+
3
4
import java .io .IOException ;
4
5
import java .util .concurrent .atomic .AtomicLong ;
5
6
import org .jruby .Ruby ;
@@ -22,7 +23,6 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
22
23
RubyClass atomicCls = concurrentMod .defineClassUnder ("JavaAtomicFixnum" , runtime .getObject (), JRUBYREFERENCE_ALLOCATOR );
23
24
24
25
atomicCls .defineAnnotatedMethods (JavaAtomicFixnum .class );
25
-
26
26
}
27
27
28
28
private static final ObjectAllocator JRUBYREFERENCE_ALLOCATOR = new ObjectAllocator () {
@@ -35,7 +35,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
35
35
public static class JavaAtomicFixnum extends RubyObject {
36
36
37
37
private AtomicLong atomicLong ;
38
- private ThreadContext context ;
39
38
40
39
public JavaAtomicFixnum (Ruby runtime , RubyClass metaClass ) {
41
40
super (runtime , metaClass );
@@ -44,14 +43,12 @@ public JavaAtomicFixnum(Ruby runtime, RubyClass metaClass) {
44
43
@ JRubyMethod
45
44
public IRubyObject initialize (ThreadContext context ) {
46
45
this .atomicLong = new AtomicLong (0 );
47
- this .context = context ;
48
46
return context .nil ;
49
47
}
50
48
51
49
@ JRubyMethod
52
50
public IRubyObject initialize (ThreadContext context , IRubyObject value ) {
53
51
this .atomicLong = new AtomicLong (rubyFixnumToLong (value ));
54
- this .context = context ;
55
52
return context .nil ;
56
53
}
57
54
@@ -61,7 +58,7 @@ public IRubyObject getValue() {
61
58
}
62
59
63
60
@ JRubyMethod (name = "value=" )
64
- public IRubyObject setValue (IRubyObject newValue ) {
61
+ public IRubyObject setValue (ThreadContext context , IRubyObject newValue ) {
65
62
atomicLong .set (rubyFixnumToLong (newValue ));
66
63
return context .nil ;
67
64
}
@@ -77,7 +74,7 @@ public IRubyObject decrement() {
77
74
}
78
75
79
76
@ JRubyMethod (name = "compare_and_set" )
80
- public IRubyObject compareAndSet (IRubyObject expect , IRubyObject update ) {
77
+ public IRubyObject compareAndSet (ThreadContext context , IRubyObject expect , IRubyObject update ) {
81
78
return RubyBoolean .newBoolean (getRuntime (), atomicLong .compareAndSet (rubyFixnumToLong (expect ), rubyFixnumToLong (update )));
82
79
}
83
80
0 commit comments