Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed taskId.isDone() issue #142

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bds.lang.Type;
import org.bds.lang.nativeMethods.MethodNative;
import org.bds.run.BdsThread;
import org.bds.run.BdsThreads;
import org.bds.task.Task;

public class MethodNative_string_exitCode extends MethodNative {
Expand All @@ -26,7 +27,7 @@ protected void initMethod() {
@Override
protected Object runMethodNative(BdsThread bdsThread, Object objThis) {
String taskId = objThis.toString();
Task task = bdsThread.getTask(taskId);
Task task = BdsThreads.getTaskNoSync(taskId);
if (task == null) return 0L;
return (long) task.getExitValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bds.lang.Type;
import org.bds.lang.nativeMethods.MethodNative;
import org.bds.run.BdsThread;
import org.bds.run.BdsThreads;
import org.bds.task.Task;

public class MethodNative_string_isDone extends MethodNative {
Expand All @@ -26,7 +27,7 @@ protected void initMethod() {
@Override
protected Object runMethodNative(BdsThread bdsThread, Object objThis) {
String taskId = objThis.toString();
Task task = bdsThread.getTask(taskId);
Task task = BdsThreads.getTaskNoSync(taskId);
if (task == null) return false;
return task.isDone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bds.lang.TypeList;
import org.bds.lang.nativeMethods.MethodNative;
import org.bds.run.BdsThread;
import org.bds.run.BdsThreads;
import org.bds.task.Task;
import org.bds.util.Gpr;

Expand All @@ -31,6 +32,9 @@ protected void initMethod() {

@Override
protected Object runMethodNative(BdsThread csThread, Object objThis) {
String taskId = objThis.toString(); Task task = csThread.getTask(taskId); if (task == null) return false; return task.isDoneOk();
String taskId = objThis.toString();
Task task = BdsThreads.getTaskNoSync(taskId);
if (task == null) return false;
return task.isDoneOk();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bds.lang.Type;
import org.bds.lang.nativeMethods.MethodNative;
import org.bds.run.BdsThread;
import org.bds.run.BdsThreads;
import org.bds.task.Task;
import org.bds.util.Gpr;

Expand All @@ -27,7 +28,7 @@ protected void initMethod() {
@Override
protected Object runMethodNative(BdsThread bdsThread, Object objThis) {
String taskId = objThis.toString();
Task task = bdsThread.getTask(taskId);
Task task = BdsThreads.getTaskNoSync(taskId);
if (task == null) return "";
return Gpr.readFile(task.getStderrFile(), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bds.lang.TypeList;
import org.bds.lang.nativeMethods.MethodNative;
import org.bds.run.BdsThread;
import org.bds.run.BdsThreads;
import org.bds.task.Task;
import org.bds.util.Gpr;

Expand All @@ -31,6 +32,9 @@ protected void initMethod() {

@Override
protected Object runMethodNative(BdsThread csThread, Object objThis) {
String taskId = objThis.toString(); Task task = csThread.getTask(taskId); if (task == null) return ""; return Gpr.readFile(task.getStdoutFile(), false);
String taskId = objThis.toString();
Task task = BdsThreads.getTaskNoSync(taskId);
if (task == null) return "";
return Gpr.readFile(task.getStdoutFile(), false);
}
}
10 changes: 10 additions & 0 deletions src/org/bds/run/BdsThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,16 @@ public Task getTask(String taskId) {
return null;
}

public Task getTaskNoSync(String taskId) {
Task task = taskDependecies.getTaskNoSync(taskId);
if (task != null) return task;
for (BdsThread bdsThread : bdsChildThreadsById.values()) {
task = bdsThread.getTaskNoSync(taskId);
if (task != null) return task;
}
return null;
}

/**
* Get all tasks
*/
Expand Down
13 changes: 13 additions & 0 deletions src/org/bds/run/BdsThreads.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Set;

import org.bds.data.Data;
import org.bds.task.Task;

/**
* All BdsThreads are tracked here
Expand Down Expand Up @@ -74,6 +75,18 @@ public synchronized void remove() {
} else throw new RuntimeException("Cannot remove thread '" + bdsThread.getBdsThreadId() + "'");
}

public static Task getTaskNoSync(String taskId) {
for (BdsThread bdsThread : bdsThreads.bdsThreadByThreadId.values() ) {
Task task = bdsThread.getTaskNoSync(taskId);
if (task != null) return task;
}
for (BdsThread bdsThread : bdsThreads.bdsThreadDone) {
Task task = bdsThread.getTaskNoSync(taskId);
if (task != null) return task;
}
return null;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
4 changes: 4 additions & 0 deletions src/org/bds/task/TaskDependecies.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public synchronized Task getTask(String taskId) {
return tasksById.get(taskId);
}

public Task getTaskNoSync(String taskId) {
return tasksById.get(taskId);
}

public synchronized Collection<String> getTaskIds() {
return tasksById.keySet();
}
Expand Down