git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit f53952e52386255d9558c848de3deb7c976779cd

remove fastproityqueue

wanderer committed on 5/10/2017, 7:59:50 AM
Parent: 318e88b7d16e694a7a34015a3c1a6b831c91c49e

Files changed

kernel.jschanged
package.jsonchanged
kernel.jsView
@@ -25,16 +25,12 @@
2525 })
2626
2727 this.vm = new opts.VM(this)
2828 this._waitingMap = new Map()
29- this._waitingQueue = new PriorityQueue((a, b) => {
30- return a.threshold < b.threshold
31- })
3229
3330 this.on('result', this._runNextMessage)
3431 this.on('idle', () => {
35- while (!this._waitingQueue.isEmpty()) {
36- const waiter = this._waitingQueue.poll()
32+ for (const [, waiter] of this._waitingMap) {
3733 waiter.resolve(this.ticks)
3834 }
3935 })
4036 }
@@ -99,28 +95,24 @@
9995 return this.ticks
10096 } else if (this.vmState === 'idle') {
10197 return this.ports.wait(threshold, fromPort)
10298 } else {
103- const promise = new Promise((resolve, reject) => {
104- this._waitingQueue.add({
99+ return new Promise((resolve, reject) => {
100+ this._waitingMap.set(fromPort, {
105101 threshold: threshold,
106102 resolve: resolve,
107103 from: fromPort
108104 })
109105 })
110- this._waitingMap.set(fromPort, promise)
111- return promise
112106 }
113107 }
114108
115109 incrementTicks (count) {
116110 this.ticks += count
117- while (!this._waitingQueue.isEmpty()) {
118- const waiter = this._waitingQueue.peek()
119- if (waiter.threshold > this.ticks) {
120- break
121- } else {
122- this._waitingQueue.poll().resolve(this.ticks)
111+ for (const [fromPort, waiter] in this._waitingMap) {
112+ if (waiter.threshold < this.ticks) {
113+ this._waitingMap.delete(fromPort)
114+ waiter.resolve(this.ticks)
123115 }
124116 }
125117 }
126118
@@ -158,6 +150,12 @@
158150
159151 const receiverEntryPort = portRef === this.entryPort ? this.parentPort : portRef
160152 const vm = await this.hypervisor.getInstance(receiverEntryPort)
161153 vm.queue(message)
154+
155+ const waiter = this._waitingMap.get(portRef)
156+ if (waiter) {
157+ waiter.resolve(this.ticks)
158+ this._waitingMap.delete(portRef)
159+ }
162160 }
163161 }
package.jsonView
@@ -27,9 +27,8 @@
2727 "license": "MPL-2.0",
2828 "dependencies": {
2929 "bn.js": "^4.11.6",
3030 "clone": "^2.1.1",
31- "fastpriorityqueue": "^0.2.4",
3231 "ipld-graph-builder": "1.1.5",
3332 "multibase": "^0.3.4",
3433 "object-clear": "^0.1.0",
3534 "primea-message": "0.0.0"

Built with git-ssb-web