Permalink
Browse files

Add double-checked locking (the safe kind) to the getting of class va…

…r table for write.
  • Loading branch information...
1 parent 0e1fea8 commit f3e08e0fd87e734934fa4f515a1887fce9a23271 @headius headius committed Apr 29, 2010
Showing with 8 additions and 2 deletions.
  1. +2 −0 src/org/jruby/IncludedModuleWrapper.java
  2. +6 −2 src/org/jruby/RubyModule.java
@@ -155,10 +155,12 @@ public IRubyObject id() {
return delegate.id();
}
+ @Override
protected synchronized Map<String, IRubyObject> getClassVariables() {
return delegate.getClassVariables();
}
+ @Override
protected Map<String, IRubyObject> getClassVariablesForRead() {
return delegate.getClassVariablesForRead();
}
@@ -2906,9 +2906,13 @@ public void setInternalModuleVariable(final String name, final IRubyObject value
// fetch/store/list class variables for this module
//
- protected synchronized Map<String, IRubyObject> getClassVariables() {
+ protected Map<String, IRubyObject> getClassVariables() {
if (classVariables == Collections.EMPTY_MAP) {
- classVariables = new ConcurrentHashMap<String, IRubyObject>(4, 0.75f, 2);
+ synchronized (this) {
+ if (classVariables == Collections.EMPTY_MAP) {
+ classVariables = new ConcurrentHashMap<String, IRubyObject>(4, 0.75f, 2);
+ }
+ }
}
return classVariables;
}

0 comments on commit f3e08e0

Please sign in to comment.