Skip to content

Commit

Permalink
exit(PID,kill) is special, it circumvents trap_exit, and generates a …
Browse files Browse the repository at this point in the history
…regular exit signal with reason killed.
  • Loading branch information
krestenkrab committed Dec 16, 2009
1 parent 60dcb1c commit 292d514
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/main/java/erjang/EInternalPort.java
Expand Up @@ -22,8 +22,6 @@
import java.nio.ByteBuffer;

import kilim.Pausable;

import erjang.ETask.State;
import erjang.driver.EDriverTask;

/**
Expand All @@ -39,8 +37,9 @@ public String toString() {
return "<port:" + task.id + ">";
}

// TODO: private final WeakReference<EDriverTask> task;
private final EDriverTask task;

public EInternalPort(EDriverTask task) {
super(ERT.getLocalNode());
this.task = task;
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/erjang/EProc.java
Expand Up @@ -49,7 +49,7 @@ public final class EProc extends ETask<EInternalPID> {
public static final EAtom am_high = EAtom.intern("high");

private static final EObject am_kill = EAtom.intern("kill");
private static final EObject am_init = EAtom.intern("init");
private static final EObject am_killed = EAtom.intern("killed");

public EFun tail;
public EObject arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8;
Expand Down Expand Up @@ -140,23 +140,27 @@ protected void link_failure(EHandle h) throws Pausable {

protected void process_incoming_exit(EHandle from, EObject reason) throws Pausable
{
if (trap_exit == ERT.TRUE) {
if (from == self_handle()) {
return;

} else if (reason == am_kill) {
this.exit_reason = am_killed;
this.pstate = State.EXIT_SIG;
this.resume();

} else if (trap_exit == ERT.TRUE) {
// we're trapping exits, so we in stead send an {'EXIT', from,
// reason} to self
ETuple msg = ETuple.make(ERT.EXIT, from, reason);
System.err.println("kill message to self: "+msg);
if (reason == am_kill && ERT.whereis(am_init)==from) {
this.exit_reason = reason;
this.pstate = State.EXIT_SIG;
return;
}
// System.err.println("kill message to self: "+msg);
mbox_send(msg);
resume(); // why did we not wake to life?

} else if (reason != am_normal) {
System.err.println("kill signal: " +reason + " from "+from);
// System.err.println("kill signal: " +reason + " from "+from);
// try to kill this thread
this.exit_reason = reason;
this.pstate = State.EXIT_SIG;
this.resume();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/erjang/driver/EDriverTask.java
Expand Up @@ -490,6 +490,9 @@ public void execute() throws Pausable {
@Override
protected void process_incoming_exit(EHandle from, EObject reason)
throws Pausable {

// TODO: do special things for reason=kill ?

System.err.println("sending exit msg to self "+this);
mbox.put(ETuple.make(ERT.EXIT, from, reason));
}
Expand Down

0 comments on commit 292d514

Please sign in to comment.