Skip to content

Commit 733d2c4

Browse files
authored
Merge pull request #8232 from headius/argv_embedding_synchronization
Synchronize state in AbstractVariable and Argv
2 parents 545313d + 9af8a68 commit 733d2c4

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

core/src/main/java/org/jruby/embed/variable/AbstractVariable.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ abstract class AbstractVariable implements BiVariable {
4949
*/
5050
protected final IRubyObject receiver;
5151
protected final String name;
52-
protected Object javaObject = null;
53-
protected Class javaType = null;
54-
protected IRubyObject rubyObject = null;
55-
protected boolean fromRuby;
52+
protected volatile Object javaObject;
53+
protected volatile Class javaType;
54+
protected volatile IRubyObject rubyObject;
55+
protected volatile boolean fromRuby;
5656

5757
/**
5858
* Constructor used when this variable is originaed from Java.
@@ -94,7 +94,7 @@ static RubyObject getTopSelf(final IRubyObject receiver) {
9494
return (RubyObject) receiver.getRuntime().getTopSelf();
9595
}
9696

97-
protected void updateByJavaObject(final Ruby runtime, Object... values) {
97+
protected synchronized void updateByJavaObject(final Ruby runtime, Object... values) {
9898
assert values != null;
9999
javaObject = values[0];
100100
if (javaObject == null) {
@@ -108,7 +108,7 @@ protected void updateByJavaObject(final Ruby runtime, Object... values) {
108108
fromRuby = false;
109109
}
110110

111-
protected void updateRubyObject(final IRubyObject rubyObject) {
111+
protected synchronized void updateRubyObject(final IRubyObject rubyObject) {
112112
if ( rubyObject == null ) return;
113113
this.rubyObject = rubyObject;
114114
this.javaType = null;
@@ -134,7 +134,7 @@ public String getName() {
134134
return name;
135135
}
136136

137-
public Object getJavaObject() {
137+
public synchronized Object getJavaObject() {
138138
if (rubyObject == null) return javaObject;
139139

140140
if (javaType != null) { // Java originated variables

core/src/main/java/org/jruby/embed/variable/Argv.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static boolean isValidName(Object name) {
114114
* invoked during EvalUnit#run() is executed.
115115
*/
116116
@Override
117-
public void inject() {
117+
public synchronized void inject() {
118118
final Ruby runtime = getRuntime();
119119

120120
final RubyArray argv = RubyArray.newArray(runtime);
@@ -141,7 +141,7 @@ else if ( javaObject instanceof String[] ) {
141141
* this variable in top self.
142142
*/
143143
@Override
144-
public void remove() {
144+
public synchronized void remove() {
145145
this.javaObject = new ArrayList();
146146
inject();
147147
}
@@ -173,7 +173,7 @@ private static void updateARGV(final IRubyObject receiver, final BiVariableMap v
173173
}
174174

175175
// ARGV appears to require special treatment, leaving javaType intact
176-
protected void updateRubyObject(final IRubyObject rubyObject) {
176+
protected synchronized void updateRubyObject(final IRubyObject rubyObject) {
177177
if ( rubyObject == null ) return;
178178
this.rubyObject = rubyObject;
179179
}
@@ -193,7 +193,7 @@ public static void retrieveByKey(RubyObject receiver, BiVariableMap vars, String
193193

194194
@Override
195195
@SuppressWarnings("unchecked")
196-
public Object getJavaObject() {
196+
public synchronized Object getJavaObject() {
197197
if ( rubyObject == null || ! fromRuby ) return javaObject;
198198

199199
final RubyArray ary = (RubyArray) rubyObject;

0 commit comments

Comments
 (0)