Created
November 29, 2011 10:53
-
-
Save anonymous/1404402 to your computer and use it in GitHub Desktop.
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
diff --git a/src/org/jruby/runtime/load/LoadService.java b/src/org/jruby/runtime/load/LoadService.java | |
index 12b3f83..506dd72 100644 | |
--- a/src/org/jruby/runtime/load/LoadService.java | |
+++ b/src/org/jruby/runtime/load/LoadService.java | |
@@ -205,6 +205,8 @@ public class LoadService { | |
protected final Map<String, JarFile> jarFiles = new HashMap<String, JarFile>(); | |
protected final Ruby runtime; | |
+ | |
+ protected final ReentrantLock requireToken = new ReentrantLock(); | |
public LoadService(Ruby runtime) { | |
this.runtime = runtime; | |
@@ -329,7 +331,17 @@ public class LoadService { | |
} | |
public boolean require(String requireName) { | |
- return requireCommon(requireName, true) == RequireState.LOADED; | |
+ boolean success = requireToken.tryLock(); | |
+ if (!success) { | |
+ runtime.getWarnings().warn("concurrent require of `" + requireName + "` detected"); | |
+ } | |
+ try { | |
+ return requireCommon(requireName, true) == RequireState.LOADED; | |
+ } finally { | |
+ if (success) { | |
+ requireToken.unlock(); | |
+ } | |
+ } | |
} | |
public boolean autoloadRequire(String requireName) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment