|
@@ -23,18 +23,36 @@ package neko.vm;
|
|
|
|
|
|
class Deque<T> {
|
|
|
var q : Dynamic;
|
|
|
+
|
|
|
+ /**
|
|
|
+ Create a message queue for multithread access
|
|
|
+ */
|
|
|
public function new() {
|
|
|
q = deque_create();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ Add a message at the end of the queue
|
|
|
+ */
|
|
|
public function add( i : T ) {
|
|
|
deque_add(q,i);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ Add a message at the head of the queue
|
|
|
+ */
|
|
|
public function push( i : T ) {
|
|
|
deque_push(q,i);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ Pop a message from the queue head. Either block until a message
|
|
|
+ is available or return immediately with `null`
|
|
|
+ */
|
|
|
public function pop( block : Bool ) : Null<T> {
|
|
|
return deque_pop(q,block);
|
|
|
}
|
|
|
+
|
|
|
static var deque_create = neko.Lib.loadLazy("std","deque_create",0);
|
|
|
static var deque_add = neko.Lib.loadLazy("std","deque_add",2);
|
|
|
static var deque_push = neko.Lib.loadLazy("std","deque_push",2);
|