Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a JRuby::Synchronized module that makes a class's methods (and it…
…s subclasses' methods) be wrapped with synchronization.
- Loading branch information
Showing
5 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/org/jruby/internal/runtime/methods/SynchronizedDynamicMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.jruby.internal.runtime.methods; | ||
|
||
import org.jruby.RubyModule; | ||
import org.jruby.runtime.Block; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
|
||
/** | ||
* | ||
* @author headius | ||
*/ | ||
public class SynchronizedDynamicMethod extends DynamicMethod { | ||
private final DynamicMethod delegate; | ||
|
||
public SynchronizedDynamicMethod(DynamicMethod delegate) { | ||
super(delegate.getImplementationClass(), delegate.getVisibility(), delegate.getCallConfig()); | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) { | ||
synchronized (self) { | ||
return delegate.call(context, self, clazz, name, args, block); | ||
} | ||
} | ||
|
||
@Override | ||
public DynamicMethod dup() { | ||
return new SynchronizedDynamicMethod(delegate); | ||
} | ||
|
||
} |