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 {
* @param executor
*/
private static void initializeNativeEventLoop(Context context, final ExecutorService executor) {
Path tmpDir;
try {
tmpDir = Files.createTempDirectory("fastr-fifo");
} catch (Exception e1) {
throw fatal("Cannot create temporary directory for event loop fifo");
}
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");
Value result = context.eval(Source.newBuilder("R", ".fastr.initEventLoop", "<init-event-loop>").internal(true).buildLiteral()).execute();
if (result.isNull()) {
return; // event loop is not configured to be run
} else if (result.getMember("result").asInt() != 0) {
System.out.println("WARNING: Native event loop unavailable. Error code: " + result.getMember("result").asInt());
} else {
final String fifoInPath = result.getMember("fifoInPath").asString();
Thread t = new Thread() {
@Override
public void run() {
......
......@@ -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.RBuiltinKind.PRIMITIVE;
import java.nio.file.Files;
import java.nio.file.Path;
import com.oracle.truffle.api.dsl.Specialization;
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.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;
/**
......@@ -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
* 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"})
public abstract class FastRInitEventLoop extends RBuiltinNode.Arg2 {
@RBuiltin(name = ".fastr.initEventLoop", kind = PRIMITIVE, behavior = COMPLEX, parameterNames = {})
public abstract class FastRInitEventLoop extends RBuiltinNode.Arg0 {
static {
Casts casts = new Casts(FastRInitEventLoop.class);
casts.arg("fifoInPath").asStringVector().findFirst();
casts.arg("fifoOutPath").asStringVector().findFirst();
Casts.noCasts(FastRInitEventLoop.class);
}
@Child private BaseRFFI.InitEventLoopNode initEventLoopNode = BaseRFFI.InitEventLoopNode.create();
@Specialization
public Object initEventLoop(String fifoInPath, String fifoOutPath) {
return initEventLoopNode.execute(fifoInPath, fifoOutPath);
public Object initEventLoop() {
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