Skip to content
Snippets Groups Projects
Commit f30b48eb authored by stepan's avatar stepan
Browse files

Allow to turn off the native event loop in FastRConfig

parent 87e4191d
No related branches found
No related tags found
No related merge requests found
...@@ -336,18 +336,13 @@ public class RCommand extends RAbstractLauncher { ...@@ -336,18 +336,13 @@ public class RCommand extends RAbstractLauncher {
* @param executor * @param executor
*/ */
private static void initializeNativeEventLoop(Context context, final ExecutorService executor) { private static void initializeNativeEventLoop(Context context, final ExecutorService executor) {
Path tmpDir; Value result = context.eval(Source.newBuilder("R", ".fastr.initEventLoop", "<init-event-loop>").internal(true).buildLiteral()).execute();
try { if (result.isNull()) {
tmpDir = Files.createTempDirectory("fastr-fifo"); return; // event loop is not configured to be run
} catch (Exception e1) { } else if (result.getMember("result").asInt() != 0) {
throw fatal("Cannot create temporary directory for event loop fifo"); System.out.println("WARNING: Native event loop unavailable. Error code: " + result.getMember("result").asInt());
}
final String fifoInPath = tmpDir.resolve("event-loop-fifo-in").toString();
final String fifoOutPath = tmpDir.resolve("event-loop-fifo-out").toString();
final int res = context.eval(Source.newBuilder("R", ".fastr.initEventLoop", "<init-event-loop>").internal(true).buildLiteral()).execute(fifoInPath, fifoOutPath).asInt();
if (res != 0) {
System.out.println("WARNING: Native event loop unavailable");
} else { } else {
final String fifoInPath = result.getMember("fifoInPath").asString();
Thread t = new Thread() { Thread t = new Thread() {
@Override @Override
public void run() { public void run() {
......
...@@ -25,10 +25,16 @@ package com.oracle.truffle.r.nodes.builtin.fastr; ...@@ -25,10 +25,16 @@ package com.oracle.truffle.r.nodes.builtin.fastr;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
import java.nio.file.Files;
import java.nio.file.Path;
import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.runtime.FastRConfig;
import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.ffi.BaseRFFI; import com.oracle.truffle.r.runtime.ffi.BaseRFFI;
/** /**
...@@ -44,19 +50,31 @@ import com.oracle.truffle.r.runtime.ffi.BaseRFFI; ...@@ -44,19 +50,31 @@ import com.oracle.truffle.r.runtime.ffi.BaseRFFI;
* uses the <code>fifoOut</code> named pipe to release the native event loop. The described * uses the <code>fifoOut</code> named pipe to release the native event loop. The described
* procedure ensures that the native event handlers handle events within a single FastR context * procedure ensures that the native event handlers handle events within a single FastR context
*/ */
@RBuiltin(name = ".fastr.initEventLoop", kind = PRIMITIVE, behavior = COMPLEX, parameterNames = {"fifoInPath", "fifoOutPath"}) @RBuiltin(name = ".fastr.initEventLoop", kind = PRIMITIVE, behavior = COMPLEX, parameterNames = {})
public abstract class FastRInitEventLoop extends RBuiltinNode.Arg2 { public abstract class FastRInitEventLoop extends RBuiltinNode.Arg0 {
static { static {
Casts casts = new Casts(FastRInitEventLoop.class); Casts.noCasts(FastRInitEventLoop.class);
casts.arg("fifoInPath").asStringVector().findFirst();
casts.arg("fifoOutPath").asStringVector().findFirst();
} }
@Child private BaseRFFI.InitEventLoopNode initEventLoopNode = BaseRFFI.InitEventLoopNode.create(); @Child private BaseRFFI.InitEventLoopNode initEventLoopNode = BaseRFFI.InitEventLoopNode.create();
@Specialization @Specialization
public Object initEventLoop(String fifoInPath, String fifoOutPath) { public Object initEventLoop() {
return initEventLoopNode.execute(fifoInPath, fifoOutPath); if (FastRConfig.UseNativeEventLoop) {
Path tmpDir;
try {
tmpDir = Files.createTempDirectory("fastr-fifo");
} catch (Exception e) {
return RDataFactory.createList(new Object[]{1}, RDataFactory.createStringVector("result"));
}
String fifoInPath = tmpDir.resolve("event-loop-fifo-in").toString();
String fifoOutPath = tmpDir.resolve("event-loop-fifo-out").toString();
int result = initEventLoopNode.execute(fifoInPath, fifoOutPath);
return RDataFactory.createList(new Object[]{result, fifoInPath, fifoOutPath},
RDataFactory.createStringVector(new String[]{"result", "fifoInPath", "fifoOutPath"}, RDataFactory.COMPLETE_VECTOR));
} else {
return RNull.instance;
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment