Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgrade kilim to new inline version; so we are in sync with Sriram's …

…latest and greatest.
  • Loading branch information...
commit 62a1feb9dc4522009b2f931b3a4bd16a8acb7566 1 parent 62fef89
@krestenkrab krestenkrab authored
View
4 .classpath
@@ -6,7 +6,7 @@
<classpathentry kind="lib" path="lib/OtpErlang.jar"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar"/>
<classpathentry kind="lib" path="lib/clojure-slim.jar"/>
+ <classpathentry kind="lib" path="lib/kilim.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry kind="lib" path="lib/kilim-0.6-krab.jar" sourcepath="/kilim/src"/>
- <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="output" path="target/test-classes"/>
</classpath>
View
4 build.xml
@@ -3,7 +3,7 @@
<property name="erjang.version" value="0.1" />
<path id="erjang.classpath">
<pathelement location="target/classes/" />
- <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/kilim.jar" />
<pathelement location="lib/OtpErlang.jar" />
<pathelement location="lib/junit.jar" />
<pathelement location="lib/clojure-slim.jar" />
@@ -13,7 +13,7 @@
<path id="erjang.testwovenclasspath">
<pathelement location="target/classes/" />
<pathelement location="target/test-classes/" />
- <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/kilim.jar" />
<pathelement location="lib/OtpErlang.jar" />
<pathelement location="lib/clojure-slim.jar" />
<pathelement location="lib/junit.jar" />
View
BIN  lib/kilim-0.6-krab.jar → lib/kilim.jar
Binary file not shown
View
12 src/main/java/erjang/EProc.java
@@ -310,6 +310,18 @@ public ELocalNode getLocalNode() {
EAtom.intern("low"),
};
+ int priority = 2;
+
+ void setPriority(int priority) {
+ if (priority >= 0 && priority <= 3) {
+ this.priority = priority;
+ }
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
/**
* @param testAtom
* @param a2
View
3  src/main/java/erjang/ETask.java
@@ -28,6 +28,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import erjang.kilim.EMailbox;
import erjang.m.erlang.ErlProc;
import kilim.Mailbox;
@@ -193,7 +194,7 @@ public EObject get_monitored_object(ERef monitor) {
static final int MAX_MAILBOX_SIZE = 1000;
- protected Mailbox<EObject> mbox = new Mailbox<EObject>(10, MAX_MAILBOX_SIZE);
+ protected EMailbox<EObject> mbox = new EMailbox<EObject>(10, MAX_MAILBOX_SIZE);
protected static enum State {
INIT, // has not started yet
View
5 src/main/java/erjang/beam/Compiler.java
@@ -65,6 +65,9 @@ public Compiler(ClassRepo repo) throws OtpAuthException, IOException {
}
public static void compile(BeamFileData data, ClassRepo repo) throws IOException {
+
+ ClassWeaver.reset();
+
// class writer, phase 4
ClassWriter cw = new ClassWriter(true);
@@ -100,7 +103,7 @@ public static void compile(BeamFileData data, ClassRepo repo) throws IOException
}
*/
boolean written = false;
- ClassWeaver cwe = new ClassWeaver(byteArray, new ErjangDetector(
+ ClassWeaver cwe = new ClassWeaver(byteArray, new ErjangDetector(
cv.getInternalClassName(), cv.non_pausable_methods));
for (ClassInfo ci : cwe.getClassInfos()) {
String name = ci.className;
View
3  src/main/java/erjang/driver/EDriverTask.java
@@ -45,17 +45,14 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import kilim.Lock;
import kilim.Pausable;
import kilim.Task;
-import erjang.EAbstractNode;
import erjang.EAtom;
import erjang.EBinary;
import erjang.ECons;
import erjang.EHandle;
import erjang.EInternalPID;
import erjang.EInternalPort;
-import erjang.ENode;
import erjang.EObject;
import erjang.EPID;
import erjang.EPeer;
View
4 src/main/java/erjang/driver/LockingDriverInstance.java
@@ -23,12 +23,8 @@
import java.nio.channels.SelectableChannel;
import java.util.concurrent.locks.ReentrantLock;
-import kilim.Lock;
import kilim.Pausable;
-import kilim.Task;
-
import erjang.EHandle;
-import erjang.EInternalPort;
import erjang.EObject;
import erjang.EPID;
import erjang.ERef;
View
3  src/main/java/erjang/driver/efile/Driver.java
@@ -21,7 +21,6 @@
import java.util.concurrent.locks.ReentrantLock;
-import kilim.Lock;
import erjang.EString;
import erjang.NotImplemented;
import erjang.driver.EDriver;
@@ -32,8 +31,6 @@
*/
public class Driver implements EDriver {
- private Lock lock;
-
@Override
public String driverName() {
return "efile";
View
1  src/main/java/erjang/driver/ram_file/Driver.java
@@ -21,7 +21,6 @@
import java.util.concurrent.locks.ReentrantLock;
-import kilim.Lock;
import erjang.EString;
import erjang.driver.EDriver;
import erjang.driver.EDriverControl;
View
190 src/main/java/erjang/kilim/EMailbox.java
@@ -0,0 +1,190 @@
+package erjang.kilim;
+
+import java.util.TimerTask;
+
+import kilim.EventSubscriber;
+import kilim.Mailbox;
+import kilim.Pausable;
+import kilim.Task;
+
+public class EMailbox<T> extends Mailbox<T> {
+
+
+ public EMailbox(int i, int maxMailboxSize) {
+ super(i,maxMailboxSize);
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public void untilHasMessage() throws Pausable {
+ while (hasMessage(Task.getCurrentTask()) == false) {
+ Task.pause(this);
+ }
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public void untilHasMessages(int num) throws Pausable {
+ while (hasMessages(num, Task.getCurrentTask()) == false) {
+ Task.pause(this);
+ }
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public boolean untilHasMessage(long timeoutMillis) throws Pausable {
+ final Task t = Task.getCurrentTask();
+ boolean has_msg = hasMessage(t);
+ long end = System.currentTimeMillis() + timeoutMillis;
+ while (has_msg == false) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ EMailbox.this.removeMsgAvailableListener(t);
+ t.onEvent(EMailbox.this, timedOut);
+ }
+ };
+ Task.timer.schedule(tt, timeoutMillis);
+ Task.pause(this);
+ tt.cancel();
+ has_msg = hasMessage(t);
+ timeoutMillis = end - System.currentTimeMillis();
+ if (timeoutMillis <= 0) {
+ removeMsgAvailableListener(t);
+ break;
+ }
+ }
+ return has_msg;
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public boolean untilHasMessages(int num, long timeoutMillis)
+ throws Pausable {
+ final Task t = Task.getCurrentTask();
+ final long end = System.currentTimeMillis() + timeoutMillis;
+
+ boolean has_msg = hasMessages(num, t);
+ while (has_msg == false) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ EMailbox.this.removeMsgAvailableListener(t);
+ t.onEvent(EMailbox.this, timedOut);
+ }
+ };
+ Task.timer.schedule(tt, timeoutMillis);
+ Task.pause(this);
+ if (!tt.cancel()) {
+ removeMsgAvailableListener(t);
+ }
+
+ has_msg = hasMessages(num, t);
+ timeoutMillis = end - System.currentTimeMillis();
+ if (!has_msg && timeoutMillis <= 0) {
+ removeMsgAvailableListener(t);
+ break;
+ }
+ }
+ return has_msg;
+ }
+
+ /**
+ * Non-blocking, nonpausing "wait-until-message-available".
+ *
+ * @param eo
+ * . If non-null, registers this observer and calls it with a
+ * MessageAvailable event when a put() is done.
+ * @return true's one, or false
+ */
+ public boolean hasMessage(EventSubscriber eo) {
+ boolean has_msg;
+ synchronized (this) {
+ int n = numMsgs;
+ if (n > 0) {
+ has_msg = true;
+ } else {
+ has_msg = false;
+ addMsgAvailableListener(eo);
+ }
+ }
+ return has_msg;
+ }
+
+ public boolean hasMessages(int num, EventSubscriber eo) {
+ boolean has_msg;
+ synchronized (this) {
+ int n = this.numMsgs;
+ if (n >= num) {
+ has_msg = true;
+ } else {
+ has_msg = false;
+ addMsgAvailableListener(eo);
+ }
+ }
+ return has_msg;
+ }
+
+ /**
+ * Non-blocking, nonpausing peek.
+ *
+ * @return buffered message if there's one, or null
+ */
+ public T peek(int idx) {
+ assert idx >= 0 : "negative index";
+ T msg;
+ synchronized (this) {
+ int n = numMsgs;
+ if (idx < n) {
+ int ic = icons;
+ msg = msgs[(ic + idx) % msgs.length];
+
+ assert msg != null : "peeked null message!";
+ } else {
+ msg = null;
+ }
+ }
+ return msg;
+ }
+
+ public T remove(final int idx) {
+ assert idx >= 0 : "negative index";
+ T msg;
+ synchronized (this) {
+ int n = numMsgs;
+ assert idx < numMsgs;
+ if (idx < n) {
+ int ic = icons;
+ int mlen = msgs.length;
+ msg = msgs[(ic + idx) % mlen];
+ for (int i = idx; i > 0; i--) {
+ msgs[(ic + i) % mlen] = msgs[(ic + i - 1) % mlen];
+ }
+ msgs[icons] = null;
+ numMsgs -= 1;
+ icons = (icons + 1) % mlen;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+ return msg;
+ }
+
+ public synchronized Object[] messages() {
+ synchronized (this) {
+ Object[] result = new Object[numMsgs];
+ for (int i = 0; i < numMsgs; i++) {
+ result[i] = msgs[(icons + i) % msgs.length];
+ }
+ return result;
+ }
+
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.