Skip to content

Commit

Permalink
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -411,6 +411,8 @@ private static final class RequireLocks {
// global lock for require must be fair
//private final ReentrantLock globalLock;

public enum LockResult { LOCKED, CIRCULAR }

private RequireLocks() {
this.pool = new ConcurrentHashMap<>(8, 0.75f, 2);
//this.globalLock = new ReentrantLock(true);
@@ -426,7 +428,7 @@ private RequireLocks() {
* @return If the sync object already locked by current thread, it just
* returns false without getting a lock. Otherwise true.
*/
private boolean lock(String requireName) {
private LockResult lock(String requireName) {
ReentrantLock lock = pool.get(requireName);

if (lock == null) {
@@ -435,11 +437,11 @@ private boolean lock(String requireName) {
if (lock == null) lock = newLock;
}

if (lock.isHeldByCurrentThread()) return false;
if (lock.isHeldByCurrentThread()) return LockResult.CIRCULAR;

lock.lock();

return true;
return LockResult.LOCKED;
}

/**
@@ -499,7 +501,7 @@ private RequireState smartLoadInternal(String file, boolean circularRequireWarni
throw runtime.newLoadError("no such file to load -- " + file, file);
}

if (!requireLocks.lock(state.loadName)) {
if (requireLocks.lock(state.loadName) == RequireLocks.LockResult.CIRCULAR) {
if (circularRequireWarning && runtime.isVerbose()) {
warnCircularRequire(state.loadName);
}

0 comments on commit fc2dd1e

Please sign in to comment.