Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First cut at timer cancelling on JVM.
  • Loading branch information
donaldh committed Apr 25, 2014
1 parent e5b3c06 commit 4872cf7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/IIOCancelable.java
@@ -0,0 +1,6 @@
package org.perl6.nqp.io;

public interface IIOCancelable {

public void cancelIt();
}
19 changes: 16 additions & 3 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -41,6 +41,7 @@
import org.perl6.nqp.io.IIOAsyncReadable;
import org.perl6.nqp.io.IIOAsyncWritable;
import org.perl6.nqp.io.IIOBindable;
import org.perl6.nqp.io.IIOCancelable;
import org.perl6.nqp.io.IIOClosable;
import org.perl6.nqp.io.IIOEncodable;
import org.perl6.nqp.io.IIOInteractive;
Expand All @@ -66,6 +67,7 @@
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;
import org.perl6.nqp.sixmodel.reprs.AsyncTaskInstance;
import org.perl6.nqp.sixmodel.reprs.CallCaptureInstance;
import org.perl6.nqp.sixmodel.reprs.ConcBlockingQueueInstance;
import org.perl6.nqp.sixmodel.reprs.ConditionVariable;
Expand Down Expand Up @@ -4392,7 +4394,7 @@ public static SixModelObject queuepoll(SixModelObject queue, ThreadContext tc) {

/* Asynchronousy operations. */

private static class AddToQueueTimerTask extends TimerTask {
private static class AddToQueueTimerTask extends TimerTask implements IIOCancelable {
private LinkedBlockingQueue<SixModelObject> queue;
private SixModelObject schedulee;

Expand All @@ -4404,6 +4406,10 @@ public AddToQueueTimerTask(LinkedBlockingQueue<SixModelObject> queue, SixModelOb
public void run() {
queue.add(schedulee);
}

public void cancelIt() {
cancel();
}
}
public static SixModelObject timer(SixModelObject queue, SixModelObject schedulee,
long timeout, long repeat, SixModelObject handle_type, ThreadContext tc) {
Expand All @@ -4415,10 +4421,17 @@ public static SixModelObject timer(SixModelObject queue, SixModelObject schedule
else
tc.gc.timer.schedule(tt, timeout);
/* XXX TODO: cancellation handle. */
return handle_type;
AsyncTaskInstance handle = (AsyncTaskInstance) handle_type.st.REPR.allocate(tc, handle_type.st);
handle.handle = tt;
return handle;
}
public static SixModelObject cancel(SixModelObject handle, ThreadContext tc) {
/* XXX TODO: support cancellation. */
AsyncTaskInstance task = (AsyncTaskInstance) handle;
if (task.handle instanceof IIOCancelable) {
((IIOCancelable)task.handle).cancelIt();
} else {
throw ExceptionHandling.dieInternal(tc, "This handle does not support cancel");
}
return handle;
}

Expand Down

0 comments on commit 4872cf7

Please sign in to comment.