Skip to content

Commit

Permalink
[GR-58708] Process thread local actions while waiting for CExt Load.
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4372
  • Loading branch information
jchalou committed Oct 7, 2024
2 parents 2afd747 + 9a34d88 commit dbd5621
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/org/truffleruby/language/loader/FeatureLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.truffleruby.language.loader;

import static org.truffleruby.language.RubyBaseNode.nil;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -21,9 +23,6 @@
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.collections.ConcurrentOperations;
Expand All @@ -32,6 +31,7 @@
import org.truffleruby.core.array.RubyArray;
import org.truffleruby.core.encoding.TStringUtils;
import org.truffleruby.core.module.RubyModule;
import org.truffleruby.core.mutex.MutexOperations;
import org.truffleruby.core.string.RubyString;
import org.truffleruby.core.string.StringOperations;
import org.truffleruby.core.support.IONodes.IOThreadBufferAllocateNode;
Expand All @@ -47,21 +47,22 @@
import org.truffleruby.language.dispatch.DispatchNode;
import org.truffleruby.platform.NativeConfiguration;
import org.truffleruby.platform.TruffleNFIPlatform;
import org.truffleruby.shared.Platform;
import org.truffleruby.shared.Metrics;
import org.truffleruby.shared.Platform;
import org.truffleruby.shared.TruffleRuby;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import static org.truffleruby.language.RubyBaseNode.nil;

public final class FeatureLoader {

private static final int PATH_MAX = 1024; // jnr-posix hard codes this value
Expand All @@ -78,7 +79,7 @@ public final class FeatureLoader {
private final Map<String, Map<String, List<RubyConstant>>> registeredAutoloads = new HashMap<>();
private final ReentrantLock registeredAutoloadsLock = new ReentrantLock();

private final Object cextImplementationLock = new Object();
private final ReentrantLock cextImplementationLock = new ReentrantLock();
private boolean cextImplementationLoaded = false;

private String cwd = null;
Expand Down Expand Up @@ -416,7 +417,8 @@ private String findFeatureWithExactPath(String path) {

@TruffleBoundary
public void ensureCExtImplementationLoaded(String feature, RequireNode requireNode) {
synchronized (cextImplementationLock) {
MutexOperations.lockInternal(context, cextImplementationLock, requireNode);
try {
if (cextImplementationLoaded) {
return;
}
Expand Down Expand Up @@ -481,6 +483,8 @@ public void ensureCExtImplementationLoaded(String feature, RequireNode requireNo
}

cextImplementationLoaded = true;
} finally {
MutexOperations.unlockInternal(cextImplementationLock);
}
}

Expand Down

0 comments on commit dbd5621

Please sign in to comment.